mutating-table

Trigger selecting child records, multiplying their values and updating parent record

♀尐吖头ヾ 提交于 2021-01-29 17:24:49
问题 I am a PL/SQL newbie and I'm struggling with a trigger. Description: I have three objects - PRODUCT, CONTAINS, ORDER. One product can have many CONTAINS and one ORDER can have many CONTAINS (basically it used to be Many-to-many relationship between PRODUCT and ORDER). Each Product has a column "value", each CONTAINS has a column "amount" and each ORDER has a column "total". When I add a new PRODUCT to ORDER via creating new CONTAINS, I want to recalculate field "total" on ORDER. Example:

SQL: trigger to prevent invalid data from being inserted into a table

浪尽此生 提交于 2020-05-16 07:44:12
问题 I have the following table: CREATE TABLE booking( booking_id NUMBER(8) NOT NULL; booking_start DATE NOT NULL; booking_end DATE NOT NULL; booking_room NUMBER(3) NOT NULL; guest_no NUMBER(5) NOT NULL; ); This table keeps track of all bookings for rooms in a particular hotel. I want to write a trigger to prevent bookings being added that overlap with the dates of previous bookings for particular rooms in the hotel. For example, let's say that room 5 is currently booked from 01 Jan 2019 to 07 Jan

Oracle SQL Trigger mutating when implemeneted

淺唱寂寞╮ 提交于 2019-12-12 03:29:33
问题 Having trouble with this trigger when it runs suring a insert or update operation. The trigger gets created without errors though. The objective is to check if the invoice_total is bigger than the total of payment_total + credit_total. Any help would be much appreciated: Create or Replace Trigger invoices_before_update_payment Before Insert or Update On invoices For Each Row Declare InvTotal Number; t_payment Number; t_credit Number; Begin select invoice_total, payment_total, credit_total

How to avoid ORA-04091 error within a trigger

橙三吉。 提交于 2019-12-04 05:41:46
问题 I have an after update trigger (Trigger A) on table A which can make changes to table B. I also have an after update trigger (Trigger B) on table B, which makes no changes, but queries table A to some sanity checking on a denormalization. So Trigger B can fire one of two ways: if I'm directly updating table B, or if I update table A and Trigger A fires, causing an update to table B. In case 2, I get an ORA-04091: table name is mutating, trigger/function may not see it error. This seems

How to avoid ORA-04091 error within a trigger

时光毁灭记忆、已成空白 提交于 2019-12-02 07:20:49
I have an after update trigger (Trigger A) on table A which can make changes to table B. I also have an after update trigger (Trigger B) on table B, which makes no changes, but queries table A to some sanity checking on a denormalization. So Trigger B can fire one of two ways: if I'm directly updating table B, or if I update table A and Trigger A fires, causing an update to table B. In case 2, I get an ORA-04091: table name is mutating, trigger/function may not see it error. This seems correct. I want to check within Trigger B if table A is "in a bad state" and early exit (the sanity checks

PL/SQL Trigger gets a mutating table error

房东的猫 提交于 2019-11-29 18:37:11
My trigger wants to check if a 'new' manager supervises no more than 5 employees. Manager supervising only 5 people are in BLOCKED_MANAGER table(ssn,numberofemployees). Finally, every update is recorded in SUPERLOG table(date,user,old_manager,new_manager). I get no compiling error about the trigger, but when I update a superssn I get this error: SQL> update employee set superssn='666666607' where ssn='111111100'; update employee set superssn='666666607' where ssn='111111100' * ERROR at line 1: ORA-04091: Table FRANK.EMPLOYEE is mutating, the trigger/function can't read it ORA-06512: a "FRANK

PL/SQL Trigger gets a mutating table error

只愿长相守 提交于 2019-11-28 12:30:49
问题 My trigger wants to check if a 'new' manager supervises no more than 5 employees. Manager supervising only 5 people are in BLOCKED_MANAGER table(ssn,numberofemployees). Finally, every update is recorded in SUPERLOG table(date,user,old_manager,new_manager). I get no compiling error about the trigger, but when I update a superssn I get this error: SQL> update employee set superssn='666666607' where ssn='111111100'; update employee set superssn='666666607' where ssn='111111100' * ERROR at line 1

INSERT trigger for inserting record in same table

半城伤御伤魂 提交于 2019-11-28 11:44:25
I have a trigger that is fire on inserting a new record in table in that i want to insert new record in the same table. My trigger is : create or replace trigger inst_table after insert on test_table referencing new as new old as old for each row declare df_name varchar2(500); df_desc varchar2(2000); begin df_name := :new.name; df_desc := :new.description; if inserting then FOR item IN (SELECT pid FROM tbl2 where pid not in(1)) LOOP insert into test_table (name,description,pid) values(df_name,df_desc,item.pid); END LOOP; end if; end; its give a error like ORA-04091: table TEST_TABLE is

Oracle triggers - problem with mutating tables

99封情书 提交于 2019-11-28 01:12:27
My tables: TableA (id number, state number) TableB (id number, tableAId number, state number) TableC (id number, tableBId number, state number) So items in TableC are TableB's children and items in TableB are TableA's children. Vice versa - items in TableA are TableB's parents and items in TableB are TableC's parents. I'd like to control state of parent items... let's say for example, that we have this data: TableA (id, state): 1, 40 TableB (id, tableAId, state): 1, 1, 40 2, 1, 60 TableC (id, tableBId, state): 1, 1, 40 2, 1, 50 3, 2, 60 4, 2, 70 Parent state should always hvae the smallest

INSERT trigger for inserting record in same table

风流意气都作罢 提交于 2019-11-27 06:30:04
问题 I have a trigger that is fire on inserting a new record in table in that i want to insert new record in the same table. My trigger is : create or replace trigger inst_table after insert on test_table referencing new as new old as old for each row declare df_name varchar2(500); df_desc varchar2(2000); begin df_name := :new.name; df_desc := :new.description; if inserting then FOR item IN (SELECT pid FROM tbl2 where pid not in(1)) LOOP insert into test_table (name,description,pid) values(df_name