Forum Stats

  • 3,839,990 Users
  • 2,262,557 Discussions
  • 7,901,118 Comments

Discussions

A trigger to give a 10 per cent discount to a regular customer

13»

Answers

  • PamNL
    PamNL Member Posts: 637 Gold Badge
    edited Dec 17, 2015 6:11AM

    Create or replace TRIGGER Ten_Percent_Discount  
    BEFORE INSERT ON Bookings 
    FOR EACH ROW 

    CURSOR C_Passengers
    IS
    SELECT StatusName
    FROM   Passengers
    WHERE  PassengerNumber = :NEW.Passengers_PassengerNumber
    ;

    l_status_name Passengers.StatusName%TYPE;

    BEGIN 

      OPEN  C_Passengers;
      FETCH C_Passengers INTO l_status_name;
      CLOSE C_Passengers;
     
      IF l_status_name = 'Regular'
      THEN
        :New.totalcost := 0.90 * :New.TotalCost;
      END IF;

    END; 

  • PamNL
    PamNL Member Posts: 637 Gold Badge
    edited Dec 17, 2015 6:11AM

    I hoped he would figure that out himself ;-)

  • 3128080
    3128080 Member Posts: 37
    edited Dec 17, 2015 6:13AM

    I did, as soon as you said foreign key in the booking table. I am like oh yes hahah.

    Thank you so much

This discussion has been closed.