最新消息: 新版网站上线了!!!

mysql存储过程(自定义函数)1337-Variable or condition declaration after cursor or handler declaration

创建mysql自定义函数时,提示错误[Err] 1337 - Variable or condition declaration after cursor or handler declaration

原因:定义变量必须放在游标之前,而我放在了游标后面,所以导致此错误

解决:变量定义放在游标定义之前

#drop function project;

create function project() returns VARCHAR(300)

begin

DECLARE proName VARCHAR(300);

DECLARE proNo VARCHAR(50);

DECLARE s int DEFAULT 0;

  DECLARE ProjCRowCur CURSOR FOR select _name,_no from techmanage.tech_project;   #我的游标定义在此处

DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s=1; 

DECLARE pid int;  #错误出现在这里,我把这个变量定义在了游标的后面

  OPEN ProjCRowCur;

  SET proName='';

  SET proNo='';

  FETCH ProjCRowCur INTO proName,proNo;

while s<>1 DO

select id INTO pid from techmanage.nodes_hierarchy where name = proName;

IF pid<>null THEN

insert into smart_quality.nodes_hierarchy (name) values (proName);

END IF;

FETCH ProjCRowCur INTO proName,proNo;

END WHILE;

CLOSE ProjCRowCur;


return proName;

end


.....

转载请注明:谷谷点程序 » mysql存储过程(自定义函数)1337-Variable or condition declaration after cursor or handler declaration