Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    18

    Unanswered: Trigger help reqd

    Hia,

    The aim of the following trigger is to ensure that when inserting on the destination table, the arrivedate is not less than the startdate from the tour table entry that has the same tourid as the new entry into destination.

    CREATE OR REPLACE TRIGGER DESTINATION_TG
    BEFORE INSERT ON DESTINATION
    DECLARE T_SDATE DATE;
    FOR EACH ROW
    BEGIN
    SELECT STARTDATE INTO T_SDATE FROM TOUR WHERE TOURID=:NEW.ARRIVEDATE;
    IF TRUNC(:NEW.ARRIVEDATE)<TRUNC(T_SDATE) THEN
    RAISE_APPLICATION_ERROR(-20100,'Destination arrivedate cannot be before tour start date';
    END IF;
    END;


    The error message is as follows:
    PLS-00103: Encountered the symbol "FOR" when expecting one of th
    following:
    begin function package pragma procedure subtype type use
    <an identifier> <a double-quoted delimited-identifier> form
    current cursor

    Thanks in advance !

    Greg

  2. #2
    Join Date
    Feb 2004
    Location
    Dublin, Ireland
    Posts
    212
    first FOR EACH then DECLARE
    Code:
    CREATE OR REPLACE TRIGGER DESTINATION_TG
    BEFORE INSERT ON DESTINATION
    FOR EACH ROW
    DECLARE T_SDATE DATE;
    BEGIN
    SELECT STARTDATE INTO T_SDATE FROM TOUR WHERE TOURID=:NEW.ARRIVEDATE;
    IF TRUNC(:NEW.ARRIVEDATE)<TRUNC(T_SDATE) THEN
    RAISE_APPLICATION_ERROR(-20100,'Destination arrivedate cannot be before tour start date';
    END IF;
    END;

  3. #3
    Join Date
    Oct 2005
    Posts
    18
    It works great. You are a legend mate, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •