Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Audit Trigger and Function
I'm trying to create a trigger that will handle any changes to the
table without re-coding. I'm having some trouble understanding why
this doesn't work...
create or replace FUNCTION "WQDBA".auditsql_fx(bindname IN VARCHAR2,
destvar IN VARCHAR2)
RETURN VARCHAR2
IS
returnme VARCHAR2(255);
BEGIN
select 'select ' || bindname || ' into ' || destvar || ' from dual'
into returnme from dual;
RETURN(returnme);
END;
and...
CREATE OR REPLACE TRIGGER "WQDBA".AUDIT_ECM_TEST before update or delete on ecm_test for each row declare
v_audit_id varchar2(35); v_username varchar2(255); cursor cur_cols is select * from dba_tab_columns where table_name = 'ECM_TEST'; cur_row cur_cols%ROWTYPE; oldval varchar2(4000); newval varchar2(4000); begin select sys_guid() into v_audit_id from dual; select user into v_username from dual; open cur_cols; loop fetch cur_cols into cur_row; exit when cur_cols%NOTFOUND;'oldval');
-- get old value
execute immediate auditsql_fx(':old.' || cur_row.column_name,
The error I am getting when attempting to update a row in ECM_TEST is
ERROR at line 1:
ORA-00905: missing keyword ORA-06512: at "WQDBA.AUDIT_ECM_TEST", line 20 ORA-04088: error during execution of trigger 'WQDBA.AUDIT_ECM_TEST'
The dynamic SQL built with the function seems to execute, but with errors. If I actually hard code this generated SQL into the trigger, it runs fine. Received on Mon Mar 31 2003 - 16:27:21 CST