我在存储过程中有以下代码:



DECLARE done INT DEFAULT FALSE;
declare v_degree int(11);
declare v_start_age smallint(6);
declare v_end_age smallint(6);
declare v_gender varchar(20);
declare v_calctable varchar(200);

SELECT calculationtable into v_calctable FROM wac.degrees where tablename = concat("cdb_" + arg_tablename);

declare cur CURSOR for select degree, start_age, end_age, belt, gender from v_calctable;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;



像这样,我将在“从wac.degrees将SELECT Calculationtable转换为v_calctable中,其中tablename = concat(“ cdb_” + arg_tablename);”这一行中出现语法错误。

如果我将其放在“声明游标”之后,则没有语法错误,但是我需要在de Cursor select语句上使用结果。

我该怎么做?

谢谢。

最佳答案

CREATE DEFINER=`root`@`localhost` PROCEDURE `my_procedure`()
BEGIN
DECLARE done INT DEFAULT FALSE;
declare v_degree int(11);
declare v_start_age smallint(6);
declare v_end_age smallint(6);
declare v_gender varchar(20);
declare v_calctable varchar(200);

SELECT calculationtable into v_calctable FROM wac.degrees where tablename = concat("cdb_" + arg_tablename);
begin                                                                   -- write here begin keyword
declare cur CURSOR for select degree, start_age, end_age, belt, gender from v_calctable;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
end;                                                                    -- end here inner block

END


当您通过另一个begin和end关键字使用inner block时
那么就没有syntask错误。
但是这个程序给您正确的结果还是不明确

关于php - MySQL游标在选择语句中带有变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40677730/

10-13 02:41