我正在尝试在oracle中运行一段代码,如果它抛出一些错误,它会退出该块。我该如何克服它?我尝试添加一些例外,但它没有用。下面是代码及其错误。
> begin for i in (
> select constraint_name , table_name
> from user_constraints
> where constraint_type ='C'
> and status = 'ENABLED' ) LOOP dbms_utility.exec_ddl_statement('alter table "'|| i.table_name || '"
> disable constraint ' || i.constraint_name); end loop; end; /
并抛出以下错误,应忽略该错误,并且该块应继续执行。
begin
*
ERROR at line 1:
ORA-30671: cannot modify NOT NULL constraint on an identity column
ORA-06512: at "SYS.DBMS_UTILITY", line 574
ORA-06512: at line 9
我尝试添加一些效果不佳的例外。
答案 0 :(得分:2)
你应该在这里使用嵌套的begin-end块,异常处理在INNER块中。
begin for i in (
select constraint_name , table_name
from user_constraints
where constraint_type ='C'
and status = 'ENABLED' )
LOOP
BEGIN
dbms_utility.exec_ddl_statement('alter table "'|| i.table_name || '"disable constraint ' || i.constraint_name);
EXCEPTION
WHEN OTHERS THEN
/* Your exception handing here. */
NULL;
END;
end loop;
end;
/