I would like to do the following in Oracle (PL/SQL) when defining a trigger:
DECLARE
pk_column_name VARCHAR(50) := 'id';
BEGIN
EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER table_a_trigger
BEFORE INSERT ON table_a
FOR EACH ROW
BEGIN
IF :new.pk_column_name IS NULL THEN /* here */
SELECT table_a_sequence.nextval
INTO :new.pk_column_name /* and here */
FROM DUAL;
END IF;
END;';
END;
I would like the variable pk_column_name (which contains the string 'id') to be "expanded" so I could write it like in above example:
IF :new.pk_column_name ....
instead of...
IF :new.id ....
I tried a lot of things like:
:new."pk_column_name"
:new.&pk_column_name
:new.:pk_column_name
Could someone please help me?
Thanks, and best regards,
Udo
select from dualthough? PL/SQL has this handy:=assignment operator. Also in 12.1 you can set this as a column default.