没有指定exception范围报错得存储过程:
create or replace procedure update_eccif_prod_set is
cursor cursor_one is select role_seq, ac_seq from temp_role_seq_ac_seq;
cur_role_seq temp_role_seq_ac_seq.role_seq%type;
cur_ac_seq temp_role_seq_ac_seq.ac_seq%type;
BEGIN
open cursor_one;
loop
fetch cursor_one into cur_role_seq, cur_ac_seq;
exit when cursor_one%notfound;
insert into ICIF.ECCIF_ROLE_PRD_AC(ROLE_SEQ, PRD_ID, AC_SEQ, MAKE_RIGHT, CHECK_RIGHT, AUTH_RIGHT, RELEASE_RIGHT) VALUES(cur_role_seq, 'ent.MCBillCheck', cur_ac_seq, 1, 0, 1, 0);
exception
when DUP_VAL_ON_INDEX then null;
end loop;
close cursor_one;
commit;
END update_eccif_prod_set;
报错信息如下:
Compilation errors for PROCEDURE ICIF.UPDATE_ECCIF_PROD_SET
Error: PLS-00103: 出现符号 "EXCEPTION"在需要下列之一时:
( begin
case declare end exit for goto if loop mod null pragma raise
return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
json_exists json_value json_query json_object json_array
Line: 12
Text: exception
Error: PLS-00103: 出现符号 "CLOSE"在需要下列之一时:
end not
pragma final instantiable persistable order overriding static
member constructor map
Line: 17
Text: close cursor_one;
分析报错信息,联想到java里的try…catch…意识到时捕捉exception时没有指定捕捉范围,程序不会自己想明白范围,所以得明确捕捉exception的范围,通过begin和end指定范围。因为分析前在网上搜了下问题,没有解答,只有几个问这问题的,也都没答案,所以记录下。正确代码如下:
create or replace procedure update_eccif_prod_set is
cursor cursor_one is select role_seq, ac_seq from temp_role_seq_ac_seq;
cur_role_seq temp_role_seq_ac_seq.role_seq%type;
cur_ac_seq temp_role_seq_ac_seq.ac_seq%type;
BEGIN
open cursor_one;
loop
fetch cursor_one into cur_role_seq, cur_ac_seq;
exit when cursor_one%notfound;
begin
insert into ICIF.ECCIF_ROLE_PRD_AC(ROLE_SEQ, PRD_ID, AC_SEQ, MAKE_RIGHT, CHECK_RIGHT, AUTH_RIGHT, RELEASE_RIGHT) VALUES(cur_role_seq, 'ent.MCBillCheck', cur_ac_seq, 1, 0, 1, 0);
exception
when DUP_VAL_ON_INDEX then null;
end;
end loop;
close cursor_one;
commit;
END update_eccif_prod_set;