I need to do a trigger but the only difference that I’m trying to do is to get a dynamic value according to ‘:new.COLUMN_NAME’ and ‘:old.COLUMN_NAME’
I’m bringing the columns of a table in a query and after that I run it with a for LOOP ..
this is my trigger:
CREATE OR REPLACE TRIGGER aft_ins_soliccambio
AFTER INSERT OR DELETE OR UPDATE
ON SEG_V_SOLICCAMBIO
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
old_col_value VARCHAR2 (4000);
new_col_value VARCHAR2 (4000);
BEGIN
FOR REC IN ( SELECT OWNER, TABLE_NAME, COLUMN_NAME
FROM all_tab_columns
WHERE OWNER = 'EUCEDA' AND (TABLE_NAME = 'SEG_V_SOLICCAMBIO')
ORDER BY column_id)
LOOP
EXECUTE IMMEDIATE ' select :new.' || REC.COLUMN_NAME || ' from dual'
INTO new_col_value;
pkg_tumi.insert_auditoria ('SEG_V_SOLICCAMBIO',
REC.COLUMN_NAME,
:new.EMPR_IDEMPRESA_N,
fn_get_pk ('SEG_V_SOLICCAMBIO', 1),
fn_get_pk ('SEG_V_SOLICCAMBIO', 2),
fn_get_pk ('SEG_V_SOLICCAMBIO', 3),
fn_get_pk ('SEG_V_SOLICCAMBIO', 4),
fn_get_pk ('SEG_V_SOLICCAMBIO', 5),
fn_get_pk ('SEG_V_SOLICCAMBIO', 6),
1,
'',
new_col_value,
SYSDATE,
NULL);
END LOOP;
END;
when I compile the trigger it doesn’t throw any error but when I try inserting a new value in the table that I’m making the trigger it throws this error:
ORA-01008: no todas las variables han sido enlazadas
ORA-06512: en “EUCEDA.AFT_INS_SOLICCAMBIO”, línea 10
ORA-04088: error durante la ejecución del disparador ‘EUCEDA.AFT_INS_SOLICCAMBIO’
Checking the problem I realized that the problem is between ‘EXECUTE IMMEDIATE ..’ but I see that is because of :new.’dynamic_column’ is not recognized. Please Help! I’m many hours with this problem and I can’t solve it.
Thanks and sorry for my english.
:newand:oldwithin triggers are somewhat inflexible. I don’t know of any way of using dynamic SQL to do what you’re attempting to do with yourEXECUTE IMMEDIATE. I suspect it’s not possible.I’m afraid the only alternatives I know about are somewhat laborious. One such alternative is to replace the
EXECUTE IMMEDIATEwith aCASEexpression such as the following:It might be possible to run a suitable SQL statement to generate all of the
WHEN ... THEN ...lines within thisCASEstatement rather than typing them all in yourself.