• MySql 游标笔记


    delimiter &&
    create PROCEDURE findProjectDetailsByProjectId(in p_userId int)
    BEGIN
       DECLARE done INT DEFAULT 0;
       DECLARE d_projectId int;
         DECLARE projectLength int;
         DECLARE c_projectId VARCHAR(100) default '';
       DECLARE findProject_cur CURSOR for
                select t1.projectId
                     from (
                        select * from  odao_admin.admin_login_user where dept_id in(
                            select deptId from odao_admin.admin_role_department where roleId  = (select role_id from odao_admin.admin_role_user where user_id = p_userId )
                        )) t,odao_wpf_project t1 where t.user_id = t1.userId and t1.`status` = 1  ;
          DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
        OPEN findProject_cur;
                  findProject_loop:LOOP
                         FETCH findProject_cur INTO d_projectId;
                            IF done THEN
                                    LEAVE findProject_loop;
                            END IF;
                            set c_projectId = CONCAT(c_projectId,CONCAT(d_projectId,',')) ;
                  END LOOP;
            CLOSE findProject_cur;

            set projectLength = (select char_length(c_projectId));

            set c_projectId = (select left(c_projectId,char_length(c_projectId)-1)  );

            set @vsql = CONCAT('select t2.*,t3.* from odao_wpf_board_task t2,(select t.boardId,boardName,t1.* from odao_wpf_board t,(select boardClassId,boardClassName from odao_wpf_boardclass where projectId in(',c_projectId,') ORDER BY orderId  ) t1 where t.boardClassId = t1.boardClassId ) t3 where t2.boardId = t3.boardId' );
          
            select @vsql;

            prepare stmt from @vsql;
         EXECUTE stmt;     
         deallocate prepare stmt;    
        
        
        
    END
    &&
    delimiter ;

  • 相关阅读:
    自学Python3.5-字符串格式化 作用域 递归
    自学Python3.2-函数分类(内置函数)
    自学Python3.1-函数基础
    自学Python2.7-collections系列
    自学Python2.6-深浅拷贝
    自学Python2.5-基本数据类型-set集合
    自学Python2.4-基本数据类型-字典dict(objct)
    自学Python2.3-基本数据类型-元组tuple(object) 方法
    自学Python2.2-基本数据类型-列表list(object)
    java通过jdbc访问mysql,update数据返回值的思考
  • 原文地址:https://www.cnblogs.com/wangfajun/p/6805871.html
Copyright © 2020-2023  润新知