I’m having problem with simple trigger command. This trigger operation will insert value into table address_rit when a person who studies at RIT is inserted into table person. Here’s the syntax for the trigger command:
CREATE OR REPLACE TRIGGER addr
AFTER INSERT ON person
FOR EACH ROW
WHEN (NEW.college = 'RIT')
BEGIN
INSERT INTO address_rit (name, address, state)
VALUES (NEW.name, NEW.address, (SELECT name FROM states WHERE NEW.statecode = states.statecode));
END;
/
The trigger is compiled but with warning. However, further inspection shows that the trigger actually has error. Here’s the error from the compilation.
PL/SQL: SQL Statement ignored ERROR
PL/SQL: ORA-00984: column not allowed here ERROR
I’m pretty sure the error is just a syntax error, but I just can’t find any solution. Let me know if I need to add more detail. Thank you very much for your help.
At a minimum, you need a colon before
NEWI’m also assuming that the query against the
STATEStable is always going to return exactly 1 row. If the database is properly normalized, though, I would expect that all the tables would have aSTATECODEcolumn rather than aSTATEcolumn and that there would be foreign keys between bothPERSONandADDRESS_RITthat reference theSTATECODEcolumn inSTATES. But, if the database is properly normalized, I would also expect that you wouldn’t have anADDRESS_RITtable that duplicated the data inPERSON. Instead,ADDRESS_RITreally ought to be a view on thePERSONtable.