Home > Enterprise >  During the trigger execution getting error : ORA-00604: error occurred at recursive SQL level 1 ORA-
During the trigger execution getting error : ORA-00604: error occurred at recursive SQL level 1 ORA-

Time:04-09

When I am trying to execute this trigger getting following error:

CREATE OR REPLACE TRIGGER create_table_trigger AFTER CREATE ON SCHEMA DECLARE
    lv_sql     VARCHAR2(5000);
   obj_name   VARCHAR2(500);
BEGIN
    obj_name := sys.dictionary_obj_name;
    lv_sql := 'EXEC SYS.DBMS_FGA.add_policy (object_schema     => ''AIM_DBA'',object_name => '''|| obj_name|| ''',policy_name => ''PROTECT_'|| obj_name || ''',audit_condition  => null,audit_column => NULL,handler_schema => ''AIM_DBA'',handler_module =>''WHERE_CLAUSE_PROTECTOR_PKG.TABLE_PROTECTOR'',enable => TRUE,statement_types => ''UPDATE,DELETE'')';
    IF
        sys.dictionary_obj_type = 'TABLE'
    THEN
        dbms_output.put_line(obj_name);
        dbms_output.put_line(lv_sql);
        EXECUTE IMMEDIATE lv_sql;
        dbms_output.put_line(lv_sql);
    END IF;

END;
/

ORA-04088: error during execution of trigger 'AIM_DBA.CREATE_TABLE_TRIGGER' ORA-00604: error occurred at recursive SQL level 1 ORA-00900: invalid SQL statement ORA-06512: at line 17

Purpose of Trigger : is whenever user create a table then after auditing should be enabled for this table .

Execution error Message:

SQL> create table aim_dba.WHERE_TST27
(
    dummy varchar2(20)
);  2    3    4
WHERE_TST27
EXEC SYS.DBMS_FGA.add_policy (object_schema     => 'AIM_DBA',object_name => 'WHERE_TST27',policy_name => 'PROTECT_WHERE_TST27',audit_condition  => null,audit_column => NULL,handler_schema =>
'AIM_DBA',handler_module =>'WHERE_CLAUSE_PROTECTOR_PKG.TABLE_PROTECTOR',enable => TRUE,statement_types => 'UPDATE,DELETE')
create table aim_dba.WHERE_TST27
*
ERROR at line 1:
ORA-04088: error during execution of trigger 'AIM_DBA.CREATE_TABLE_TRIGGER'
ORA-00604: error occurred at recursive SQL level 1
ORA-00900: invalid SQL statement
ORA-06512: at line 17*

CodePudding user response:

EXEC (or EXECUTE) is SQL*Plus and related client shorthand for an anonymous block. It isn't something that's recognised by the SQL or PL/SQL engines.

Change your call to use BEGIN/END instead:

lv_sql := 'BEGIN SYS.DBMS_FGA.add_policy (... statement_types => ''UPDATE,DELETE''); END;';
--         ^^^^^                                                                   ^^^^^^

I'm not sure why you are using dynamic SQL here though, you can just call SYS.DBMS_FGA.add_policy directly.

But either way, from your subsequent ORA-04022 error, it looks like DBMS_FGA is performing DDL that requires a dictionary lock on the same table, so this isn't going to work. You'll need to rethink your approach.

  • Related