If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Trigger trouble, seeking assistance

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-01-11, 09:25
jsturm01 jsturm01 is offline
Registered User
 
Join Date: Nov 2011
Posts: 1
Trigger trouble, seeking assistance

Hello,

First time on this forum, and very new to SQL and Oracle. I'm trying to get this trigger to compile properly; all I want it to do at this point is fire if a location being entered in a new row hasn't been entered in any previous row before. Here's the code:

Code:
CREATE OR REPLACE TRIGGER SIGHTINGS_FOREIGN_KEY
BEFORE INSERT ON SIGHTINGS
FOR EACH ROW
BEGIN
  IF :NEW.location NOT IN (SELECT location FROM SIGHTINGS) 
  THEN dbms_out.put('not working yet');
  END IF;
END;
At this point, the errors are:
Quote:
Error(2,3): PL/SQL: Statement ignored
Error(2,27): PLS-00405: subquery not allowed in this context
Any help or suggestions would be appreciated. Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 11-01-11, 09:42
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Quote:
Originally Posted by jsturm01 View Post
I'm trying to get this trigger to compile properly; all I want it to do at this point is fire if a location being entered in a new row hasn't been entered in any previous row before.
Throw away that trigger and create unique constraint on SIGHTINGS.LOCATION column. Choose VALIDATE/NOVALIDATE and ENABLE/DISABLE state options according to your exact needs.

By the way, your pseudo code would do nothing as DBMS_OUTPUT only writes to the output buffer; it would not stop/affect executing the INSERT statement which fired it.
Reply With Quote
Reply

Tags
oracle, sql, trigger

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On