A trigger for give a discount of 10 percent for a regular customer
Hello
I am trying to create a trigger to give a 10% discount on the 'TotalCost' field in the table of reservations, if the 'statusname' is regular in the table of passengers. Here's what I come up with so far. But I know that its bad. Can you please help?
create or replace TRIGGER Ten_Percent_Discount BEFORE UPDATE ON Bookings FOR EACH ROW BEGIN UPDATE Bookings b SET b.TotalCost = 0.10 * TotalCost WHERE Passengers.StatusName = 'Regular'; END;
Thank you
Fareedh
Assuming you have a passenger_id in your table reservations probably use something like this
Eate or replace TRIGGER Ten_Percent_Discount
BEFORE the update ON bookings
FOR EACH LINE
CURSOR C_Passengers
IS
SELECT Status_Name
OF passengers
WHERE Passenger_Id =: NEW. Passenger_Id
;
l_status_name Passengers.Status_Name%TYPE;
BEGIN
OPEN C_Passengers.
Look FOR C_Passengers IN l_status_name;
CLOSE C_Passengers;
IF l_status_name = "Normal".
THEN
: New.total_cost = 0.90 *: New.Total_Cost;
END IF;
END;
Tags: Database
Similar Questions
-
Mr President.
What is wrong with this sequence, it does not work when, after 3 inserts, I add a new record with the trigger it gives an error.
--SL_CUSTOMERS table data INSERT INTO SL_CUSTOMERS VALUES(1,'Kamrul Hasan',NULL,NULL,'Moghbazar', 'Dhaka','0456789123',NULL,NULL,NULL,'Y',NULL); INSERT INTO SL_CUSTOMERS VALUES(2,'Rabiul Alam',NULL,NULL,'Motijheel', 'Dhaka','0567891234',NULL,NULL,NULL,'Y',NULL); INSERT INTO SL_CUSTOMERS VALUES(3,'Shahed Hasan',NULL,NULL,'2-G/1,2-2,Mirpur', 'Dhaka','0678912345',NULL,NULL,NULL,'Y',NULL);
CREATE SEQUENCE "ALIZA"."SL_CUSTOMERS_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE ; CREATE OR REPLACE TRIGGER SL_CUSTOMERS_TRG BEFORE INSERT ON "ALIZA"."SL_CUSTOMERS" FOR EACH ROW BEGIN IF :NEW.CUSTOMER_ID IS NULL OR :NEW.CUSTOMER_ID < 0 THEN SELECT SL_CUSTOMERS_SEQ.nextval INTO :NEW.CUSTOMER_ID FROM DUAL; END IF; END; /
When I try to insert several records with the seq.nextval it gives error
violation of primary key.
INSERT INTO "ALIZA"."SL_CUSTOMERS" (CUSTOMER_NAME) VALUES ('sdfsd') ORA-00001: unique constraint (ALIZA.SL_CUSTOMERS_PK) violated ORA-06512: at line 1 One error saving changes to table "ALIZA"."SL_CUSTOMERS": Row 4: ORA-00001: unique constraint (ALIZA.SL_CUSTOMERS_PK) violated ORA-06512: at line 1
Concerning
Mr President.
I find the solution by creating a function before the triiger
as below
CREATE SEQUENCE "ALIZA"."SL_CUSTOMERS_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE ; CREATE OR REPLACE FUNCTION get_SL_CUSTOMERS_vId RETURN VARCHAR2 AS BEGIN RETURN SL_CUSTOMERS_SEQ.NEXTVAL; END; / CREATE OR REPLACE TRIGGER SL_CUSTOMERS_TRG BEFORE INSERT ON "ALIZA"."SL_CUSTOMERS" FOR EACH ROW DECLARE dummy VARCHAR2(200); BEGIN dummy := get_SL_CUSTOMERS_vId(); :NEW.CUSTOMER_ID := dummy; END; /
It works very well
Thank you all for the suggestions.
Concerning
-
Create the trigger for multiple users
I am trying to create a trigger for a DDL event which gives an error for 2 users when they try to create a database object or a table.
Here is my code. When ran it gives me the following error: "WARNING: trigger created with errors of complication."
Any idea would be appreciated.
Thank you!
CREATE OR REPLACE TRIGGER trigger_before_create_object
BEFORE YOU CREATE ON THE DATABASE
BEGIN
IF USER = USER OR "VPD_CLERK1" = "DBSEC_CLERK."
THEN
RAISE_APPLICATION_ERROR (' you do not have the privilege to create tables or other database objects.) Contact your administrator if you need the privilege. ") ;
END IF;
END;
Published by: mkmety on April 20, 2013 12:10Welcome to the forum!
Whenever you post provide your Oracle version 4-digit
>
I am trying to create a trigger for a DDL event which gives an error for 2 users when they try to create a database object or a table.Here is my code. When ran it gives me the following error: "WARNING: trigger created with errors of complication."
Any idea would be appreciated.
Thank you!
>
And to alert you to the need to view the errors you got. If you did you will see this:
>
PLS-00306: wrong number or types of arguments in the call to "RAISE_APPLICATION_ERROR.
>
Oracle cannot raise your exception if you:1. do not define an exception to throw
2. don't tell Oracle how exception to throwSee the section "Defining your own Error Messages (procedure RAISE_APPLICATION_ERROR)" in the doc of the PL/SQL language
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/errors.htm#i1871This article has examples that show how to raise your exceptions.
-
How can I write the trigger for the global temporary Table
Hi Grus,
How can I write the trigger for the global temporary Table.
I created the TWG with trigger using the script below.
CREATE A GLOBAL_TEMP GLOBAL TEMPORARY TABLE
(
EMP_C_NAME VARCHAR2 (20 BYTE)
)
ON COMMIT PRESERVE ROWS;
CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
BEFORE DELETE, UPDATE OR INSERT
ON GLOBAL_TEMP
REFERRING AGAIN AS NINE OLD AND OLD
FOR EACH LINE
BEGIN
INSERT INTO VALUES EMPNAME (: OLD.) EMP_C_NAME);
END;
/
trigger was created successfully, but her would not insert EMPNAME Table...
Please guide if mistaken or not? If not wanting to give a correct syntax with example
Thanks in advance,
Arun M MBEGIN INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME); END;
you are referencing old value in insert stmt. BEGIN INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME); END;
then run your app, it works very well...
CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP ( EMP_C_NAME VARCHAR2(20 BYTE) ) ON COMMIT PRESERVE ROWS; CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP BEFORE DELETE OR UPDATE OR INSERT ON GLOBAL_TEMP REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW BEGIN dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo'); INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME); dbms_output.put_line(:OLD.EMP_C_NAME); END; / create table EMPNAME as select * from GLOBAL_TEMP where 1=2 insert into GLOBAL_TEMP values('fgfdgd'); commit; select * from GLOBAL_TEMP; select * from EMPNAME; output: 1 rows inserted commit succeeded. EMP_C_NAME -------------------- fgfdgd 1 rows selected EMP_C_NAME -------------------- fgfdgd 1 rows selected
He got Arun
Published by: OraclePLSQL on December 28, 2010 18:07
-
Hello
Generate a rectangular signal of AO on AO0 (white) while playing a Sin on AO1 (red) signal. I want to record on AIx, while the tension of the rectangular signal is max.
Currently I physically route AO0 to PFI0 and use it as a trigger for the analog input:
But the VI fails because AIx does not detect the edge of the PFI0 of the trigger. How to fix the VI to work proberly?
Thank you
VI can be found here: http://forums.ni.com/t5/Discussions-au-sujet-de-NI/USB-6251-router-Analog-output-pour-trigger-Analog...
Hafiz asean.support solution:
I looked at your code and there was a problem with the installation of the acquisition of the chain to HAVE.
Acquisition of analog input has been configured incorrectly
In your code, you set the program to use calendar settings based on a waveform. However, when you build the waveform, I believe you accidentally used the frequency instead of the dt of the waveform to build. Removal of the inverse function ensures that the correct values are passed in. Originally, the AI sampling period was put at about 4000 seconds, which in turn causes the trigger to expire.
Take note that the production and the acquisition is not exactly at the same time. You can see the following diagram:
Thank you haha!
-
Help design a trigger for an analog voltage signal
Hello guys,.
I have a real problem one design trigger for an application, what I do is to power a motor and measure consumption current and voltage during each operation. What I would do is to begin to acquire the signal once the voltage rises to a certain value and finish when it falls to a certain value. The equipment I use is a cDAQ 9178 with a NI9205 and 9221 modules.
Any help / samples / detailed explanation will be really appreciated. I have no idea on how to work with the outbreak of the vi in Labview.
Concerning
SergeArmz
Finally after a lot of research, tests and many developments, this is a VI that I developed and who is able to do what I was looking for. Thanks to the guys who helped me out to understand how solve my problem.
For all those who may have the same problem I had, I enclose the VI.
And of course if you can improve on what I did will be great, I think it's the purpose of this forum
See you soon!
SergeArmz
-
How to write the trigger for update or delete multiple columns in a table?
Hello
I create one in the form of table of sample_emp. In that, every time I want to change of name, team_id, team_leader_id, supervisor_id, manager_id it must store the update-able and old values of those in the job_history table. When I write the trigger for which it shows "ORA-04082 new or the old value not table level triggers. Here is my emp_table. My table also similar job_history like this. Need your help.
Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6 Heading 7 8 header Header 9 EMP_ID EMP_NAME DESIGNATION TEAM_ID TEAM_LEADER_ID EMPLOYEE MANAGER_ID HIRE_DATE RELIEVED_DATE --
Thank you.
Hi Joel,.
Venky_prs wrote:
Hello
I create one in the form of table of sample_emp. In that, every time I want to change of name, team_id, team_leader_id, supervisor_id, manager_id it must store the update-able and old values of those in the job_history table. When I write the trigger for which it shows "ORA-04082 new or the old value not table level triggers. Here is my emp_table. My table also similar job_history like this. Need your help.
Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6 Heading 7 8 header Header 9 EMP_ID EMP_NAME DESIGNATION TEAM_ID TEAM_LEADER_ID EMPLOYEE MANAGER_ID HIRE_DATE RELIEVED_DATE --
Thank you.
You can try something like this given below to complete the historical table on update and delete.
create or replace TRIGGER "CLONE_EMP_UPDATE_DELETE" BEFORE DELETE OR UPDATE ON EMP FOR EACH ROW DECLARE PRAGMA autonomous_transaction; BEGIN INSERT INTO JOB_HISTORY("EMP_ID","EMP_NAME","DESIGNATION","TEAM_ID","TEAM_LEADER_ID","SUPERVISOR_ID","MANAGER_ID" ,"HIRE_DATE","RELIEVED_DATE") VALUES(:OLD.EMP_ID,:OLD.EMP_NAME,:OLD.DESIGNATION,:OLD.TEAM_ID,:OLD.TEAM_LEADER_ID,:OLD.SUPERVISOR_ID, :OLD.MANAGER_ID,:OLD.HIRE_DATE, :OLD.RELIEVED_DATE); COMMIT; END;
Hope this helps you,
Kind regards
Jitendra
-
Hi guys,.
I need to do a temporary simple audit on all updates on a table.
That's why I create a trigger for her...
However, I need to capture the SQL statement to make the update as well... However I have no way to do it, because it is always replaced by a SQL code I run to get the SESSION ID...
Here is the trigger...
----------------------
create or replace
alert_setting_trg relaxation
before the update on user_alert_settings
for each line
declare
number of v_sid;
v_username varchar2 (100);
v_osuser varchar2 (100);
v_machine varchar2 (100);
v_program varchar2 (100);
v_module varchar2 (100);
v_prevsqlid varchar2 (100);
v_sqltext varchar2 (100);
Start
SELECT SYS_CONTEXT ('USERENV', 'SID')
IN v_sid
FROM DUAL;
SELECT the username, osuser, machine, program, module, PREV_SQL_ID
IN v_username, v_osuser, v_machine, v_program, v_module, v_prevsqlid
SESSION $ v where SID = v_sid;
SELECT sql_text
IN v_sqltext
V $ sqltext
WHERE SQL_ID = v_prevsqlid;
INSERT INTO alert_settings_log
VALUES (sysdate, v_sid, v_username, v_osuser, v_machine, v_program, v_module, v_sqltext,: new.user_id,: new.service_grp,: new.alert_setting_id,: old.alert_active,: new.alert_active);
end;
Now the problem is that...
the capture of SQL statement will always be
SELECT SYS_CONTEXT ('USERENV', 'SID')
IN v_sid
FROM DUAL;
and not the UPDATE table statement.
1st quarter) I have to get the SID of the session before I could know what SQL it is running.
However, once I get the SID, the SQL to UPDATE the SID is run changes the SQL that gets the SID.
What can I do?
Rgds,
NoobInstead of to the request in three steps, do it in 1. Replace all three of your queries with something like:
SELECT s.username, s.osuser, s.machine, s.program, s.module, q.sql_text INTO v_username, v_osuser, v_machine, v_program, v_module, v_sqltext FROM v$session s, v$sql_area q WHERE s.sid = SYS_CONTEXT('USERENV','SID') and s.prev_sql_id = q.sql_id
John
-
FRM-40735: trigger for INSERTION after raised unhandled exception ORA-25207
Hello
I am trying to create custom applications. In that when creating custom responsibility I get the following error
FRM-40735: trigger for INSERTION after raised unhandled exception ORA-25207
I know ORA-25207 is related to the activation of the queues, but how do I find out which queue this error is ponting at.
File alertlog Checked, $APPLCSF / $APPLLOG found nothing.
Any help is appreciated
Concerning
TaherPL see if the steps described in MOS Doc 211095.1 (11, 5 - AP: Frm-40735: trigger of sur-Commit not triggered managed Ora - 25207 Exception on APXPAWKB) can help.
It is an odd error and should not occur when you create custom responsibilities. You have customizations/triggers/customizations enabled on the form of accountability?
HTH
Srini -
trigger for update field in a table with the sum of the fields to another table
My experience in creation of triggers and pl/sql in general can be described in terms of oracle with the null value. I practiced by creating arrays and applications on my personal server at home to help me with some of my work related tasks. Right now I am creating a trigger which will, after insert, update, delete on the update of the table assignment_time_track the area of the time_spent on the table of assignments with the sum of the time_spent on the assignment_time_track table fields. I hope that run on the sentence it is clear to the people other than me. I tried this script on my own using the tool of creation of trigger for Oracle Database Express Edition, but I get the following error:
Create a trigger failed, for the following reason:
ORA-06552: PL/SQL: ORA-06553 finished Compilation unit analysis: PLS-320: the declaration of the type of the expression is incomplete or incorrect
Here is my attempt to create the trigger on my own.
create or replace trigger "ASSIGNMENT_TIME_TRACK_T1".
AFTER
INSERT or update or delete on 'ASSIGNMENT_TIME_TRACK '.
for each line
Start
update assignments
Set time_spent = (select sum (time_spent)
of assignment_time_track
where assignment_time_track.name = assignments.name);
end;
/
If what I posted is not clear or more detail is needed, let me know and I will respond with a full description of tables and my goals for each table. Thanks in advance for any help. I also gladly accepts links to tutorials or lessons that explain how to do this kind of thing.
Published by: bobonthenet on March 9, 2009 14:01I think I understand what you mean :)
Rather than use a trigger to keep the master table (assignments) in sync with the time spent on the details, it would be much easier to use a query to do this, maybe creating a view.
Something along the lines of
SQL> create table assignments 2 (id number primary key 3 ,name varchar2(10) 4 ); Table created. SQL> SQL> create table assignment_time_tbl 2 (id number primary key 3 ,assid number references assignments 4 ,time_spent number 5 ); Table created. SQL> SQL> insert into assignments 2 select rownum 3 , 'a' 4 from all_objects 5 where rownum < 5 6 / 4 rows created. SQL> SQL> insert into assignment_time_tbl 2 select rownum 3 , rownum 4 , rownum * 3 5 from all_objects 6 where rownum < 5 7 / 4 rows created. SQL> SQL> commit; Commit complete. SQL> SQL> SQL> select a.id 2 , a.name 3 , (select sum (time_spent) 4 from assignment_time_tbl 5 where assid = a.id 6 ) 7 from assignments a 8 / ID NAME (SELECTSUM(TIME_SPENT)FROMASSIGNMENT_TIME_TBLWHEREASSID=A.ID) ---------- ---------- ------------------------------------------------------------- 1 a 3 2 a 6 3 a 9 4 a 12
-
who is the best 4 db Trigger for auto-differentiels?
Hello
Who is the best 4 db Trigger for auto-incrementielle of an id ...?
With the help of a sequence and the sequence of call in an insert...
Or by using the following code:
----------------------------------------
or both are the same thing... ?SELECT NVL(MAX (SCDEDULE_ID+1),0) INTO V_SCDEDULE_ID FROM INSP_DAILY_SCHEDULE ; EXCEPTION when NO_data_found then null; WHEN OTHERS then null; END;
Pls advice me..... !
Kind regards
Abdetu...As already mentioned, you should definitely use sequences, because they are the only mechanism that works in multi user environments. Each user will receive a different schedule_id assigned, while the use of the nvl - max method two sessions when it is running at the same time will acquire the same schedule_id. You can of course lock the entire table to work around this problem, but which leads to questions of scalabilty. Sequences are also faster, as can be seen in the following example:
SQL> create table insp_daily_schedule 2 ( schedule_id number primary key 3 , other_columns varchar2(100) 4 ) 5 / Tabel is aangemaakt. SQL> create sequence myseq 2 / Reeks is aangemaakt. SQL> create package schedule_api 2 as 3 procedure add_daily_schedule_nvlmax 4 ( p_other_columns in insp_daily_schedule.other_columns%type 5 ); 6 procedure add_daily_schedule_sequence 7 ( p_other_columns in insp_daily_schedule.other_columns%type 8 ); 9 end schedule_api; 10 / Package is aangemaakt. SQL> create package body schedule_api 2 as 3 procedure add_daily_schedule_nvlmax 4 ( p_other_columns in insp_daily_schedule.other_columns%type 5 ) 6 is 7 l_schedule_id insp_daily_schedule.schedule_id%type; 8 begin 9 select nvl(max(schedule_id),0)+1 10 into l_schedule_id 11 from insp_daily_schedule 12 ; 13 insert into insp_daily_schedule 14 ( schedule_id 15 , other_columns 16 ) 17 values 18 ( l_schedule_id 19 , p_other_columns 20 ); 21 end add_daily_schedule_nvlmax 22 ; 23 procedure add_daily_schedule_sequence 24 ( p_other_columns in insp_daily_schedule.other_columns%type 25 ) 26 is 27 begin 28 insert into insp_daily_schedule 29 ( schedule_id 30 , other_columns 31 ) 32 values 33 ( myseq.nextval 34 , p_other_columns 35 ); 36 end add_daily_schedule_sequence 37 ; 38 end schedule_api; 39 / Package-body is aangemaakt. SQL> set timing on SQL> begin 2 for i in 1..10000 3 loop 4 schedule_api.add_daily_schedule_sequence(lpad('*',100,'*')); 5 end loop; 6 end; 7 / PL/SQL-procedure is geslaagd. Verstreken: 00:00:00.93 SQL> / PL/SQL-procedure is geslaagd. Verstreken: 00:00:00.92 SQL> / PL/SQL-procedure is geslaagd. Verstreken: 00:00:00.92 SQL> begin 2 for i in 1..10000 3 loop 4 schedule_api.add_daily_schedule_nvlmax(lpad('*',100,'*')); 5 end loop; 6 end; 7 / PL/SQL-procedure is geslaagd. Verstreken: 00:00:01.32 SQL> / PL/SQL-procedure is geslaagd. Verstreken: 00:00:01.68 SQL> / PL/SQL-procedure is geslaagd. Verstreken: 00:00:01.32
The only counter-argument that can be given for the nvl - max method, is that it is the independent database, while Oracle sequences are used by Oracle only as far as I know. But since independence database should never be a goal because it leads to poor applications and poor database design because it can only operate features that each database has, this argument is hardly any value.
Kind regards
Rob. -
our company had Adobe CS 3, we ship adobe creative cloud member of more than 2 years now. But we must all credit for the existing customer.
There is no current discount for loyal customers. You must have missed the opportunity to get a discount at the end of May. Before that if you were an owner of Creative Suite, you can get the first year at a reduced rate.
-
Can someone tell me if I should delete the following startup programs for Windows 7: customer ComcastAntispy and FlexNet connect? I have read several articles and most of them say that I should remove.
Original title: startup programs in Windows 7
They are third-party programs and only you can know if you need and uninstall, if so
-
What is the phone number for the Adobe Customer Service
What is the phone number for the Adobe Customer Service
800-833-6687 (the only one from 05:00 - 19:00 PST, Monday to Friday day US).
To the link below, click on the still need help? option in the blue box below and choose the option to chat or by phone...
Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache. If it fails to connect, try to use another browser.
Creative cloud support (all creative cloud customer service problems)
http://helpx.Adobe.com/x-productkb/global/service-CCM.html ( http://adobe.ly/19llvMN )
-
What is the best practice for a 'regular' Server VMware and VDI environment?
What is the best practice for a "regular" VMware Server and VDI environment? A single environment (ESXi and SAN) can accommodate two if it is a whole new configuration? Or even better to keep separate?
Enjoying inputs.
Quick and dirty answer is that "it depends."
serioulsy, it depends really two things budget and IO. If you had the money for two without then buy two and don't have to host your server environment and the other for VDI desktop, their IO profiles are completely different.
If this is not the case, try to keep each type of use for their own dedicated LUN.
Maybe you are looking for
-
No individual sent the sms time? Can I turn it on?
So now my new iPhone 6s I don't see anyone sent or received time on my Sms? on my old iPhone I could hold a message for a long time and he would show the details of time, is there a way for this switch or see it on this phone? Or is it only together
-
Drive hard full cannot explain
HP Mini1000, FQ729AV, WinXP PC A 16 GB hard drive. In Explorer, I right click on C: in the left pane, and then click Properties. It shows that the used space is 16 + GB, free space is 326 KB. Then I go to the left with the directories pane and visibl
-
Light sensor ambient flow 8.
Is flow 8 supports, ambient light sensor? Changing light/brightness manually, it's really annoying...
-
Message keeps Occuring invalid Version of Windows Vista...
I have an old laptop MX6440 Gateway and I bought it new from the store with XP installed on it. Later, I upgraded the laptop for Windows Vista. The upgrade, that I bought at Best Buy was legal and I paid for it. I installed upgrading Windows Vista to
-
sevice pack 1-Oxc01a001d problem.
I just installed service pack 1. Now I get any mode of starting a computer in la! Oxc01a001d! (\registry\Machine\COMPONENTS\DerivedData...) Message. I don't know what to do. I have an alienware (for most dell products) computer, this computer used to