【问题标题】:How to ignore an ERROR while executing a block of code in ORACLE在 ORACLE 中执行代码块时如何忽略错误
【发布时间】:2015-12-18 03:13:38
【问题描述】:

我正在尝试在 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

我尝试添加效果不佳的异常。

【问题讨论】:

  • 您还有问题吗?
  • 嗨,Mahesh,对不起,现在很清楚了。谢谢。 :)

标签: oracle exception plsql oracle11g


【解决方案1】:

您应该在这里使用嵌套的 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;
  /

【讨论】:

    猜你喜欢
    • 2018-06-21
    • 2015-09-22
    • 1970-01-01
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    • 2021-03-09
    相关资源
    最近更新 更多