Question about deferred constraints

Roeland

Member³
Hi,

I have placed an unique contraint on a table and made it DEFERRABLE (that is initially immediate).

Now I'm writing a package where I want to make this constraint "Deferred".

So I write the following inside a procedure before the DML code:

PL/SQL: ORA-00922: missing or invalid option
What am I doing wrong? Can't you change this constraint inside a package?

Any help is very much appreciated.

Thank you,

Roeland
 
You can't issue DDL inside PL/SQL try the following

Code:
procedure my_proc
is
begin
  execute immediate 'SET CONSTRAINT MY_UNIQUE_CONSTRAINT DEFERRED';
  ..
  <dml code goes here>
end;
 
Please note, executing DDL (altering tables, triggers, constraints etc.) always commits. Using DDL inside PL/SQL should be used with caution to avoid unwanted commits.

Best regards
Claus Pedersen
 
@Claus: You're right didn't think about that, but if you 'hide' the ddl statement in an autonomous transaction you won't be troubled by the implicit commit caused by the ddl.
 
Hi Pimpollo,

Thanks for correcting this and for enhancing my knowledge on this subject. It may come handy in the future.

Nice to see such an old post again ;-)
 
Back
Top