SQL 未触发继续处理程序
SQL continue handler is not triggered
IBM i V7R1M0。每当发生错误时,我需要继续处理一条语句,据我所知,例如:
DECLARE CONTINUE HANDLER 似乎是答案,所以
我有一个非常简单的程序,如下所示:
exec SQL create or replace procedure test_prod1
(in test2 decimal(1,0))
language sql modifies sql data
begin
declare continue handler for sqlexception
begin end;
update DUPEPF set INT2 = test2;
end;
据我所知,这意味着只要发生错误(例如违反唯一键),SQL 语句就会继续,但事实并非如此。只要出现键冲突并且不处理下一行,该语句就会停止。我很困惑为什么会这样
您的继续处理程序正在工作...
您的过程忽略了 UPDATE
语句抛出的错误并继续。除了没有别的事可做。
仅仅因为您的过程忽略了错误,并不意味着数据库可以忽略其更新语句处理中的错误。
编辑
处理程序改变了存储过程或 UDF 处理错误的方式...将它们视为解决数据库抛出的 "catch" 错误的一种方式。他们不会阻止数据库首先抛出这些错误
有道理吗?
为了完成您想要做的事情,您需要使用自己的光标,例如...
create or replace procedure test_prod1
(in test2 decimal(1,0))
language sql modifies sql data
begin
declare myInt integer;
DECLARE DUPLICATE_KEY CONDITION FOR SQLSTATE '23505';
DECLARE END_OF_TABLE CONDITION FOR SQLSTATE '02000';
declare test_cursor cursor for
select int2 from DUPEPP for update;
declare exit handler for END_OF_TABLE
close test_cursor;
declare continue handler for DUPLICATE_KEY
begin end;
open test_cursor;
fetch_loop:
LOOP
fetch next from test_cursor into myInt;
update dupepf set int2 = test2
where current of test_cursor;
END LOOP fetch_loop;
end;
IBM i V7R1M0。每当发生错误时,我需要继续处理一条语句,据我所知,例如:
DECLARE CONTINUE HANDLER 似乎是答案,所以
我有一个非常简单的程序,如下所示:
exec SQL create or replace procedure test_prod1
(in test2 decimal(1,0))
language sql modifies sql data
begin
declare continue handler for sqlexception
begin end;
update DUPEPF set INT2 = test2;
end;
据我所知,这意味着只要发生错误(例如违反唯一键),SQL 语句就会继续,但事实并非如此。只要出现键冲突并且不处理下一行,该语句就会停止。我很困惑为什么会这样
您的继续处理程序正在工作...
您的过程忽略了 UPDATE
语句抛出的错误并继续。除了没有别的事可做。
仅仅因为您的过程忽略了错误,并不意味着数据库可以忽略其更新语句处理中的错误。
编辑
处理程序改变了存储过程或 UDF 处理错误的方式...将它们视为解决数据库抛出的 "catch" 错误的一种方式。他们不会阻止数据库首先抛出这些错误
有道理吗?
为了完成您想要做的事情,您需要使用自己的光标,例如...
create or replace procedure test_prod1
(in test2 decimal(1,0))
language sql modifies sql data
begin
declare myInt integer;
DECLARE DUPLICATE_KEY CONDITION FOR SQLSTATE '23505';
DECLARE END_OF_TABLE CONDITION FOR SQLSTATE '02000';
declare test_cursor cursor for
select int2 from DUPEPP for update;
declare exit handler for END_OF_TABLE
close test_cursor;
declare continue handler for DUPLICATE_KEY
begin end;
open test_cursor;
fetch_loop:
LOOP
fetch next from test_cursor into myInt;
update dupepf set int2 = test2
where current of test_cursor;
END LOOP fetch_loop;
end;