0
DROP PROCEDURE IF EXISTS Cursor_Test;# MySQL returned an empty result set (i.e. zero rows).

DELIMITER $$

CREATE PROCEDURE Cursor_Test()
BEGIN

  DECLARE Project_Number_val VARCHAR( 255 );
  DECLARE Project_List_val VARCHAR(255);



  DECLARE no_more_rows BOOLEAN;
  DECLARE loop_cntr INT DEFAULT 0;
  DECLARE num_rows INT DEFAULT 0;


  DECLARE projects_cur CURSOR FOR
    SELECT Project_Id
    FROM Project_Details;


  DECLARE CONTINUE HANDLER FOR NOT FOUND
    SET no_more_rows = TRUE;


  OPEN projects_cur;
  select FOUND_ROWS() into num_rows;

  the_loop: LOOP

    FETCH  projects_cur
    INTO   Project_Number_val;


    IF no_more_rows THEN
        CLOSE projects_cur;
        LEAVE the_loop;
    END IF;

SET Project_List_val=CONCAT(`Project_Number_val`,'_List')

-

> ---> **Please check am I doing CONCAT correct here?**


Insert Into test (Panel_Id) select Panel_Id from Project_List_val where Project_Number_val='9';  

> --->**Is this taking 9_List as table name?**


    SET loop_cntr = loop_cntr + 1;
  END LOOP the_loop;


  select num_rows, loop_cntr;


END $$# MySQL returned an empty result set (i.e. zero rows).


DELIMITER 

有什么建议么?大家好,

我在存储过程中有一个名为 Project_Number 的变量,它是 varchar 类型。

我的要求是“对于每个项目编号查询表 project_Number_List 从列表中获取结果并插入其他表”

可以说,Project_Number 可能是这样的 22,21,34,43,434 我需要查询的对应表是这样的 22_List, 21_List,34_List .....

我正在使用光标遍历 Project_Number 但我的问题是如何混合 project_number 和 _list 即 22_list 来查询表 22_List

4

3 回答 3

7

试试这个:

SET Project_List_val=CONCAT(Project_Number_val,'_List')
于 2013-02-12T08:16:55.377 回答
4
SET Project_List_val=CONCAT(Project_Number_val,'_List');

不要将单引号 For Project_Number_val 可变。

于 2013-02-12T08:20:31.233 回答
2

你的 var 调用是错误的,试试这个:

 SET Project_List_val = CONCAT(Project_Number_val,'_List')
于 2013-02-12T08:18:01.777 回答