1

I am trying to run a block of code in oracle and it exits the block if it throws some error. How do I overcome it? I tried adding some exceptions and it didn't work. Below is the code and its error.

> 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; /

and it throws the following error which should be ignored and the block should continue executing.

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

I tried adding Exceptions which didn't work well.

2
  • DO you still face issue? Commented Sep 21, 2015 at 13:37
  • Hi Mahesh, Sorry, Its clear now. Thanks. :) Commented Sep 22, 2015 at 4:16

1 Answer 1

3

You should use, nested begin-end block here, the exception handling been inside the INNER block.

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;
  /
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.