Sunday, November 05, 2006

Execution of LOGON trigger results in ORA-12841(COPIED from METALINK)

The information in this article applies to:
Oracle Server - Enterprise Edition - Version: 8.1.7.4 to 10.2.0.0
This problem can occur on any platform.

Symptoms
A LOGON trigger has been created to enable a PARALLEL DML during the session

i.e.

CREATE OR REPLACE TRIGGER LOG_ON AFTER
LOGON ON DATABASE
BEGIN
execute immediate 'alter session enable parallel dml';
END;



LOGON trigger throws the following error:

ORA-604: error occurred at recursive SQL level 1
ORA-12841: Cannot alter the session parallel DML state within a transaction
ORA-6512: at line 2
Cause
Parallel DML cannot be enabled during the transaction.

i.e.

SQL> insert into emp values ('fdfg');

1 row created.

SQL> alter session enable parallel dml;
ERROR:
ORA-12841: Cannot alter the session parallel DML state within a transaction

-- The transaction should be completed before enabling the PARALLEL DML

SQL> commit;

Commit complete.

SQL> alter session enable parallel dml;

Session altered.

Logon trigger executes as an autonomous transaction and that is why the error ORA-12841 occurs.
Fix
1) invoke "alter session enable parallel dml" in other autonomous transaction through a function.

2) call a function in a trigger

e.g.

create or replace function myfunc return number is
PRAGMA AUTONOMOUS_TRANSACTION;
x number:=0;
begin
execute immediate 'alter session enable parallel dml';
return x;
end;


create or replace trigger log_on after
logon on database
declare
x number;
begin
x := myfunc;
end;
References
Bug 3129124 - Logon Trigger Works In 8i But Fails In 9i With Ora-12841

No comments: