Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trigger to check the existing values

899280Apr 2 2012 — edited Apr 3 2012
I have a table 'table1' with column' 'ID'.The table1 are loaded with many records.

Now need to create a trigger which will check any new record which is inserting will have the ID already exists in the table1. I wrote the following trigger but giving error 'Sub Query not allowed here'. How can I achieve this. Thank in Advance


CREATE OR REPLACE TRIGGER check_col
BEFORE INSERT
ON table1 for each row
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;


BEGIN


if :new.id not in (select disticnt id from table1) then

raise_application_error (-20999,'New id not allowed');


end if;



END ;
/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 1 2012
Added on Apr 2 2012
9 comments
5,708 views