Assuming I have a trigger specification like this:
create table "t" (
"i" number(10)
);
create or replace trigger "trg"
before insert on "t"
referencing new as "n"
for each row
begin
null;
end;
How can I reference the "n"
identifier from within the body? None of these work:
"n"."i" := 2;
:"n"."i" := 2;
":n"."i" := 2;
:n."i" := 2;
All of these attempts compile, but produce this error when trying to insert into the table:
ORA-04098: trigger 'TEST.trg' is invalid and failed re-validation
Obviously, I can avoid quoting the variable name, but 1) this is about code generation from a tool, which has to get this syntax right regardless of the quoting, and 2) I'm curious about the correct syntax.
Bind variables
In the CREATE TRIGGER
docs, there's a reference to (emphasis mine):
In the trigger_body of a simple trigger or the tps_body of a compound trigger, a correlation name is a placeholder for a bind variable.
It seems that bind variables in general do not support quoting, e.g. while this works:
BEGIN
EXECUTE IMMEDIATE 'BEGIN dbms_output.put_line(:x); END;' USING 'a';
END;
This, or any similar syntax, doesn't:
BEGIN
EXECUTE IMMEDIATE 'BEGIN dbms_output.put_line(:"x"); END;' USING 'a';
END;
So, this seems consistent, but I'm still curious about the specification of why I can declare the name like this, but cannot seem to reference it.
The database version is Oracle Database 18c Express Edition Release 18.0.0.0.0