Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
A trigger to give a 10 per cent discount to a regular customer
Answers
-
Hi,
This is just for an assignment. I am really really new PL/SQL haha. I agree with you guys, but I had to write a trigger and the database itself is fairly simple.
Thank you so much for you help. Can you just tlel on when the tirgger will execute and explain what it is doing?
Thanks,
Fareedh
-
As Blu has already suggested you should not be using Trigger, but the line of code giving you error is due to "=" instead of ":="
the code should have line as below
:New.TotalCost := 0.90 * :New.TotalCost;
-
Hi
I am also getting this error
Error(7,26): PLS-00049: bad bind variable 'NEW.PassengerNumber'
Sorry to be so annoying
Thanks
-
It will fire when you update anything in the bookings table.
I think your trigger should actually be on insert, because if you create a new booking it wll get the full cost and ONLY when you update the booking the passenger gets the 10% discount.
So you can test by entering a passenger in the table, then insert something in the booking table (nothing happens). Now update the booking (ANY field) and your total cost will be reduced.
Now for the fun part, update again ;-).
And again
And again ...
-
And to be sure you get the point .. check TotalCost after each update ;-)
-
PamNL wrote: It will fire when you update anything in the bookings table. I think your trigger should actually be on insert, because if you create a new booking it wll get the full cost and ONLY when you update the booking the passenger gets the 10% discount.
Even better it should be on INSERT and UPDATE, so it can fire whether it's a new data or updated data, providing the UPDATE is coded to give a reduction on the original cost/price and not to keep applying discounts again and again on the current value.
-
Hi
I am also getting this error
Error(7,26): PLS-00049: bad bind variable 'NEW.PassengerNumber'
Sorry to be so annoying
Thanks
-
That's fine .. what does your passenger and booking table look like? I had to guess on the foreign key in bookings to go the passenger table ..
-
SELECT PASSENGERNUMBER, TITLE, STATUSNAME, FIRSTNAME, SURNAME, FIRSTLINEADDRESS, SECONDLINEADDRESS, CITY, POSTCODE, CONTACTTELEPHONENUMBER, EMAILADDRESS, JOURNEY_JOURNEYNUMBER FROM PASSENGERS ;
SELECT BOOKINGID, DATEOFBOOKING, TRAVELDATE, STOPS, TOTALADULTS, TOTALCHILDREN, CARDTYPE, CARDNUMBER, EXPIRYDATE, TOTALCOST, PASSENGERS_PASSENGERNUMBER, SERVICES_SERVICENUMBER FROM BOOKINGS ;
ABove is booking and passengers
Thanks
-
The problem with this approach is that the trigger fires every time the booking record is updated for any reason, and each time it does the cost is reduced by 10%. Customer changes delivery date? knock off 10%. Customer changes order amount? knock off another 10% etc...
Possibly better to have a new column: discount_amount, that has a default value of 0, but you set it to 10% for regular customers.
How will you deal with cases where the passenger status is changed to regular for a passenger that has existing booking records?