Question on Trigger Code
Hello. I'm trying to put a trigger onto table1 that will eventually cause data to be inserted into table2. My immediate problem is getting the new data to be inserted into variables. Here's and example of what I have:
CREATE OR REPLACE TRIGGER tr_table1_insert
AFTER INSERT ON table1
FOR EACH ROW
SELECT :new.emp1 INTO v_emp1;
This gives me the following error:
PLS-00103: Encountered the symbol ";" when expecting one of the following: . ( , % from
I can't see what's wrong with the syntax. Can someone help me? Thanks.
First, in Oracle SELECT needs a FROM clause. The system table DUAL is provided for this, although in principle it's no different from any other table.
However, PL/SQL has an assignment operator ":=", so you could code for example,
v_emp1 emp.emp1%TYPE := :new.emp1;
...code using v_emp1...
But why go to the trouble of duplicating the variable at all? I would just use :new.emp1 directly in the code.
Click Here to Expand Forum to Full Width