macrohu

记事本
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

db2 declare cursor 42601错误解决

Posted on 2013-08-14 17:39  macrohu  阅读(8993)  评论(0)    收藏  举报

使用以下代码创建存储过程时,报42601错误,

declare continue handler for sqlstate not found set v_end = 1;

declare c1 cursor with hold for select * from tab1;

Error:在 "" 后面找到异常标记 "<cursor declaration>"。预期标记可能包括:"<SQL statement>"。. SQLCODE=-104, SQLSTATE=42601

语句本身没有问题的,排查了半天,才发现是个db2 比较恶心的规定导致的:DB2 声明变量要有序的要求:首先声明:普通变量;其次声明:游标;最后声明:condition handler。

将游标的声明位置放到handler之前,问题解决

declare c1 cursor with hold for select * from tab1;

 

declare continue handler for sqlstate not found set v_end = 1;