HiveBrain v1.2.0
Get Started
← Back to all entries
debugMinor

If an 'after' DDL trigger causes an error, is the DDL rolled back?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
afterrollederrortriggertheddlbackcauses

Problem

It has been suggested that DDL is logically performed something like this:

begin
    COMMIT;
    perform any appropriate pre-DDL trigger code;
    do the ddl;
    perform any appropriate post-DDL trigger code;
    COMMIT;
exception
    when others then
         ROLLBACK;
         raise;
end;


Which would suggest that any error in a trigger would cause the DDL to be rolled back. Is this the case?

Solution

The answer, at least on 11.2, is "It depends":

This create is rolled back:

create trigger trig_foo after create on schema
begin
raise_application_error(-20001, 'Dont do it!');
end;
/
--
create table foo as select level as id from dual connect by level

But this
truncate is not:

create table foo as select level as id from dual connect by level

Context

StackExchange Database Administrators Q#9700, answer score: 9

Revisions (0)

No revisions yet.