Skip to content
Advertisement

How to insert data into table even if trigger fails?

Oracle 11.1

I have custom logging table where I insert data:

I have a trigger that runs on a specific table which does some checkings. My problem is: when the trigger fails, I want to be able to log some data into the log_table.

Trigger:

The following code doesn’t work. I tried to use EXECUTE IMMEDIATE maybe to force it, but didn’t work. I know that in case of an error, there is automatically a table rollback (which means that the INSERT command is cancelled), but I need a way to do this. Any help?

Advertisement

Answer

Yes, PRAGMA AUTONOMOUS_TRANSACTION seems to be the answer. Here is the working code:

Defined a procedure for logging:

and the trigger which calls the procedure:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement