Execute_query after on-insert trigger
Hello.
I use on-insert trigger to insert data into database and then i want to execute_query so i can see all records including the last one i inserted.
How can i workaround the problem with using execute_query or go_item in (or after) on-insert trigger?
Thanks.
Hi,
you cannot execute navigational or query built-ins when in a transaction control point (ON-INSERT).
ON-, KEY triggers replace the functionality of the events they fire upon.
You can use the KEY-COMMIT Trigger to do this. For instance:
<<KEY-COMMIT>>
Commit_Form; -- all validation triggers are fired
-- WHEN SUCCESSFUL
Go_Block ('BLOCK_NAME');
Execute_Query;
Go_Block ('STARTING_BLOCK_NAME');
-- END KEY-COMMIT
Regargds,
Hans
Similar Messages
-
After update insert trigger is not working correctly
Hello experts!
I created an after insert/update trigger and what strikes me is that it is not working as expected.
The trigger launches a procedure that does an insert in a second table if values in the triggered table ("my_table") are altered.
The problem is that the values in my second table, which are correlated to "my_table", are not changed with the correct values right away. The trigger and insert trails behind!
I have to update twice for the values to appear in my second table. Only then, the data of the first update will be inserted into the second table wheras the parent table ("my_table") will hold the latest values.
Do you have an idea what could be wrong?
create or replace
trigger myscheme.after_update_insert_set_tw
after update or insert
on myscheme.my_table
for each row
declare
begin
pr_my_table_tw_sync_sk(:new.lng_falle, :new.int_fallennummer, :new.lng_schaedling, :new.objectid);
end;Brgds,
SebOkay I'll give my best to explain what my procedure is supposed to do and what the table structure is like. I hope it'll help you to help me :-)
My parent table is called fangzahlen and is created as follows:
CREATE TABLE "BORKI"."FANGZAHLEN"
( "OBJECTID" NUMBER(10,0) NOT NULL ENABLE,
"LNG_FALLE" NUMBER(10,0) NOT NULL ENABLE,
"LNG_BEARBEITER" NUMBER(10,0),
"DATE_DATUM" DATE DEFAULT SYSDATE NOT NULL ENABLE,
"INT_FALLENNUMMER" NUMBER(4,0) NOT NULL ENABLE,
"LNG_SCHAEDLING" NUMBER(2,0) NOT NULL ENABLE,
"INT_VOLUMEN" NUMBER(10,0),
"INT_ANZAHL" NUMBER(10,0),
"INT_ANTEIL_JUNGKAEFER" NUMBER(3,0),
"BOOL_KOEDERWECHSEL" NUMBER(1,0),
CONSTRAINT "PK_FANGZAHLEN" PRIMARY KEY ("OBJECTID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE,
CONSTRAINT "CHECK_DATE_DATUM" CHECK ("DATE_DATUM" >= '1.apr.2006') ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;It holds values such as:
OBJECTID,"LNG_FALLE","LNG_BEARBEITER","DATE_DATUM","INT_FALLENNUMMER","LNG_SCHAEDLING","INT_VOLUMEN","INT_ANZAHL","INT_ANTEIL_JUNGKAEFER","BOOL_KOEDERWECHSEL"
97548,"39","1081","08.04.10","1","2","","220","","0"
97534,"39","1081","06.04.10","1","2","","100","","-1"My subtable is called tbl_test and created with:
CREATE TABLE "BORKI"."TBL_TEST"
( "OBJECTID" NUMBER(12,0) NOT NULL ENABLE,
"LNG_FALLE" NUMBER(10,0),
"DATE_DATUM" DATE,
"INT_FALLENNUMMER" NUMBER(4,0),
"LNG_SCHAEDLING" NUMBER(2,0),
"INT_VOLUMEN" NUMBER(10,0),
"INT_ANZAHL" NUMBER(10,0),
"LNG_FANGZAHLEN" NUMBER(12,0)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;Okay, this were the prerequisites!
Let's concentrate on the trigger and procedure:
The purpose of the procedure is to insert data into tbl_test once a record in "fangzahlen" has been updated or inserted.
Tbl_test holds the mean average values (int_anzahl) for a number of collected items (lng_schaedling).
I need to insert date values for the combination of each lng_fangzahlen, lng_schaedling, lng_falle and int_fallennr into tbl_test.
If I had the following data in table fangzahlen:
97548,"39","1081","08.04.10","1","2","","220","","0"
97534,"39","1081","06.04.10","1","2","","100","","-1"the query in the insert section of my procedure returns the following data when run manually:
97534 31.03.10 16,667 (null) 1 39 2
97548 06.04.10 110 (null) 1 39 2Now, I need to generate the dates between the first and the second objectid (column 1 in the data above).
Hence,
97534 31.03.10 16,667 (null) 1 39 2
97534 01.04.10 16,667 (null) 1 39 2
97534 02.04.10 16,667 (null) 1 39 2
97534 03.04.10 16,667 (null) 1 39 2
97534 04.04.10 16,667 (null) 1 39 2
97534 05.04.10 16,667 (null) 1 39 2
97534 06.04.10 16,667 (null) 1 39 2
97548 07.04.10 110 (null) 1 39 2
97548 08.04.10 110 (null) 1 39 2
My problem is thatthe values above will only appear after I do another update to table fangzahlen or insert a new record into it. Theoretically the result above should be inserted right away?
Below is my procedure, which might give you a better idea of what I am trying to do! Please excuse this rather awkward explanation. If you need more info please don't hesitate to ask for it!
create or replace
Procedure "PR_FANGZAHLEN_TW_SYNC_SK"
Pr_falle Number,
Pr_fallennummer Number,
Pr_schaedling Number,
Pr_objectid Number)
Is
Y Number (10);
pragma autonomous_transaction;
Begin
-- first all records should be deleted from the subtable i.e. tbl_test
delete from borki.tbl_test where lng_falle = pr_falle
and int_fallennummer = pr_fallennummer
and lng_schaedling = pr_schaedling
and date_datum > '31.03.2010';
commit;
For Rec In
(select objectid lng_fangzahlen,
date_datum,
prev_date,
(date_datum - prev_date) difference_in_days,
round((
case
when nvl(int_volumen,0) > 0
and lng_schaedling = 1
then int_volumen * 40
when nvl(int_volumen,0) > 0
and lng_schaedling = 2
then int_volumen * 550
when nvl(int_anzahl,0) > 0
then int_anzahl
end ) / (date_datum - prev_date),3) counted_bugs,
int_fallennummer,
lng_falle,
lng_schaedling
from
(select objectid,
date_datum,
case
when lag(date_datum) over(order by date_datum) is null
then to_date('31.03.2010')
else lag(date_datum) over(order by date_datum)
end as prev_date,
int_volumen,
int_anzahl,
int_fallennummer,
lng_falle,
lng_schaedling
from borki.fangzahlen
where lng_falle = pr_falle
and int_fallennummer = pr_fallennummer
and lng_schaedling = pr_schaedling
and date_datum > '31.03.2010'
-- and objectid = pr_objectid
order by date_datum desc
order by date_datum asc
Loop
Y := 1;
While Y < rec.difference_in_days + 1
Loop
Insert
Into tbl_test
lng_fangzahlen,
date_datum,
int_anzahl,
int_volumen,
int_fallennummer,
lng_falle,
lng_schaedling
select objectid lng_fangzahlen,
prev_date +Y,
round((
case
when nvl(int_volumen,0) > 0
and lng_schaedling = 1
then int_volumen * 40
when nvl(int_volumen,0) > 0
and lng_schaedling = 2
then int_volumen * 550
when nvl(int_anzahl,0) > 0
then int_anzahl
end ) / (date_datum - prev_date),3) counted_bugs,
int_volumen,
int_fallennummer,
lng_falle,
lng_schaedling
from
(select objectid,
date_datum,
case
when lag(date_datum) over(order by date_datum) is null
then to_date('31.03.2010')
else lag(date_datum) over(order by date_datum)
end as prev_date,
int_volumen,
int_anzahl,
int_fallennummer,
lng_falle,
lng_schaedling
from borki.fangzahlen
where lng_falle = pr_falle
and int_fallennummer = pr_fallennummer
and lng_schaedling = pr_schaedling
and date_datum > '31.03.2010'
order by date_datum desc
order by date_datum asc
commit;
Y := Y + 1;
End Loop;
End Loop; -- end of cursor
Exception
When No_data_found Then
Null;
When Others Then
-- Consider logging the error and then re-raise
Raise;
End "PR_FANGZAHLEN_TW_SYNC_SK"; -
After/before update trigger
Hi All
Does any onoe know
what 's the difference between after update/insert trigger and before update/insert trigger
on database tables.Hi
The basic diffrence is
Before Update triggers before the table is updated and
After update triggers after the table is updated but
before the implicit commit fires.
therefore when you raise the application error a
implicit Rollback happens and the record is not commited.
Regards
Shajesh Nair
Deloitte.
[email protected] -
Using Database Change Notification instead of After Insert Trigger
Hello guys! I have an after insert trigger that calls a procedure, which in turn is doing an update or insert on another table. Due to mutating table errors I declared the trigger and procedure as autonomously transactional. The problem is, that old values of my main tables are inserted into the subtable since the after insert/update trigger is fired before the commit.
My question is how can I solve that and how could I use the change notification package to call my procedure? I now that this notification is only started after a DML/DDL action has been commited on a table.
If you could show me how to carry out the following code with a Database Change Notification I'd be delighted. Furthermore I need to know if it suffices to set up this notification only once or for each client seperately?
Many thanks for your help and expertise!
Regards,
Sebastian
declare
cnumber number (6);
begin
select count(*) into cnumber from (
select case when (select date_datum
from
(select f.date_datum,
row_number() over (order by f.objectid desc) rn
from borki.fangzahlen f
where lng_falle = :new.lng_falle
and int_fallennummer = :new.int_fallennummer
and lng_schaedling = :new.lng_schaedling
and date_datum > '31.03.2010'
where rn=1) < (select date_datum
from
(select f.date_datum,
row_number() over (order by f.objectid desc) rn
from borki.fangzahlen f
where lng_falle = :new.lng_falle
and int_fallennummer = :new.int_fallennummer
and lng_schaedling = :new.lng_schaedling
and date_datum > '31.03.2010'
where rn=2) then 1 end as action from borki.fangzahlen
where lng_falle = :new.lng_falle
and int_fallennummer = :new.int_fallennummer
and lng_schaedling = :new.lng_schaedling
and date_datum > '31.03.2010') where action = 1;
if cnumber != 0 then
delete from borki.tbl_test where lng_falle = :new.lng_falle
and int_fallennummer = :new.int_fallennummer
and lng_schaedling = :new.lng_schaedling
and date_datum > '31.03.2010';
commit;
pr_fangzahlen_tw_sync_sk(:new.lng_falle, :new.int_fallennummer, :new.lng_schaedling);It looks like you have an error in line 37 of your code. Once you fix that the problem should be resolved.
-
Before or After insert trigger on HR_API_TRANSACTION_VALUES
I am on the termination page of SSHR and after entering the details when clcked on 'Next' the validations built in before / after insert trigger of HR_API_TRANSACTION_VALUES does not retrieve the data and the error 'No data found' is displayed.
We do not have AME approval. When clicked on 'Next' it goes to the review page. When I do a select on the HR_API_TRANSACTION_VALUES the data do exists but the validation does not work.
We have Oracle HRMS 11i with database as 11g.
Please give a resolution at the earliest.you can use
hr_transaction_api.set_varchar2_value
or
hr_transaction_api.set_number_value
based on what type of value that you want to update -
Hello all,
I have a question about after insert trigger. Will be new row inserted and commited if after insert trigger returns error? Thank you.
regards,
MihaWhat is the error that u r facing?
there could multiple reasons for that. Basically, u can't put commit in the trigger (unless it is an autonomous transaction). Share the pseudo-code of u r triiger, so that , problem can be identified.
Cheers,
Ram Kanala -
Calling of Stored Procedure in After Insert Trigger
Can I call a Stored Procedure in After Insert Trigger ?
Please send a sample code (good example) of After Insert Trigger.
Thanks.Kishore,
I have two table WLCS_ORDER, WLCS_ORDER_LINE
WLCS_ORDER - It holds order header information like
ORDER_ID
CUSTOMER_ID
TRANSACTION_ID
STATUS
ORDER_DATE
SHIPPING_METHOD
SHIPPING_AMOUNT
SHIPPING_CURRENCY
PRICE_AMOUNT
PRICE_CURRENCY
SHIPPING_GEOCODE
SHIPPING_STREET1
SHIPPING_STREET2
SHIPPING_CITY
SHIPPING_STATE
SHIPPING_COUNTRY
SHIPPING_POBOX
SHIPPING_COUNTY
SHIPPING_POSTAL_CODE
SHIPPING_POSTAL_CODE_TYPE
SPECIAL_INSTRUCTIONS
SPLITTING_PREFERENCE
ORDER_SUBTOTAL
WLCS_ORDER_LINE - It holds all order lines information like
ORDER_LINE_ID
QUANTITY
PRODUCT_ID
TAX_AMOUNT
TAX_CURRENCY
SHIPPING_AMOUNT
SHIPPING_CURRENCY
UNIT_PRICE_AMOUNT
UNIT_PRICE_CURRENCY
MSRP_AMOUNT
MSRP_CURRENCY
DESCRIPTION
ORDER_ID
TOTAL_LINE_AMOUNT
Relation between WLCS_ORDER, WLCS_ORDER_LINE is one to many.
For each WLCS_ORDER row, one or more order lines will insert into WLCS_ORDER_LINE table.
For each new row in WLCS_ORDER table, I have to update the following columns in both the tables with my maths.
WLCS_ORDER
shipping_amount
price_amount
order_subtotal
WLCS_ORDER_LINE
shipping_amount
I thought I can do this in after insert trigger, But if it is not possible, Please give the best way to fulfill this requirement.
I appreciate your help.
Have a great day.
Srinivas -
Pre-insert trigger is not firing after post built-in
Hi,
I have a 10g form in which Post built-in is used in When-button-pressed Trigger. After the post command I am checking some condition,by using the same record which I have posted.But it is not working.
I have also put the message in the pre-insert trigger but the message is not displaying.
But the same form iis working fine in form 6i, as I have migrated the forms from form 6i to 10g.Yes, In that block there are other items also. I have made the required property no for all the items.
what exactly we have is
(if x=y then)on some condition check
POST;
After that, form have a select statement in which it is selecting the same row which is being posted above.
if the select statement gives count of row zero
raise form_trigger_failure is fired.
and in the pre-insert trigger form is assigning a value to a block item. -
After Insert Trigger with DML on the subject table?
I am trying to set up e-mail notifications, so I created a procedure, which accepts the argument of an id. In the procedure, it queries the table and sends out mail based on the result set. (in the trigger, I pass in the value of :NEW.id). The procedure then queries the table for that row id.
First, for the after update I was getting the error:
ORA-04091: table is mutating, trigger/function may not see it ORA-06512
So, I was advised to do in the declare block: pragma autonomous_transaction; I did that, and that solved the problem there. SO I did the same in the after insert trigger, but then I get the error:
ORA-00060: deadlock detected while waiting for resource ORA-06512
I asked our DBA and he said you are not able to query the table of which the trigger is a subject of. I thought it would be possible since its After insert or update?
Can anyone offer any suggestions ? :)
Thanks,
TrentAny reason why it would work in an after update trigger then?
So, I was advised to do in the declare block: pragma autonomous_transaction; I did that, and that solved the problem therePRAGMA AUTONOMOUS_TRANSACTION "bends" the restriction against SQL against base table.
It is the equivalent to tap dancing across a mine field.
You might get the desired results most of the time or you might get a tasty surprise when you least expect it.
What happens to your application in the future, if/when the UPDATE has a ROLLBACK issued & PRAGMA AUTONOMOUS_TRANSACTION has successfully completed?
Inquiring minds would like to know the answer. -
Invoke execute_query after an on-update trigger
Hi there,
i try to do an execute_query after an on-update trigger.
The trigger can't do this. When, and with wich trigger can i make the block to 'refresh'??
Thanx in advance.
Edwin SmalHello,
ON-UPDATE trigger fires in the validation process (commit)
put the execute_query after the commit_form (which is placed in a KEY-COMMIT trigger)
Francois -
After insert trigger with :NEW.ROWID
Hi All,
I am using a After insert trigger to generate history record as following:
CREATE TABLE TB_TEST (classID number(3), classNm varchar2(12));
CREATE TABLE TB_HIST_TEST (hist_dttm timestamp(6), classID number(3), classNm varchar2(12));
CREATE or REPLACE TRIGGER air_test AFTER INSERT ON tb_test FOR EACH ROW
BEGIN PK_SRVC.CRT_NewRec('TB_TEST', 'TB_HIST_TEST', :new.ROWID); END:
In PK_SRVC package, I use the following statment to create new record in TB_HIST_TABLE:
Insert into tb_hist_test (hist_dttm, classID, classNm)
values (select systimestamp, classID, classNm from tb_test where rowid = ROWID )
The trigger DOES fire when a new row is inserted into TB_TEST. However there is no record inserted into TB_HIST_TEST. Any suggestion?
Thanks,The PK_SRVC.CRT_NewRec is a generic service package that can be shared by many tables. It uses dynamic SQL to get all the collumns for different tables based on USER_TAB_COLUMNS. The following is the code of this package:
PROCEDURE CRT_NewRec ( p_TableName IN VARCHAR2, p_AudTableName IN VARCHAR2, p_RowID)
IS
TYPE TabCol_RecTyp IS RECORD (COLUMN_NAME VARCHAR2(30), COLUMN_ID NUMBER);
TYPE TabCol_CurTyp IS REF CURSOR;
c_TabCol TabCol_CurTyp;
rc_TabCol TabCol_RecTyp;
v_Sql_TabCol VARCHAR2(1000);
v_ColNames VARCHAR2(1000);
v_Sql VARCHAR2(1000);
PRAGMA AUTONOMOUSE_TRANSCATION;
BEGIN
v_SQL_TabCol := ' SELECT column_name, column_id FROM USER_TAB_COLUMNS'
|| ' WHERE table_name = ' || CHR(39) || p_TableName || CHR(39)
|| ' ORDER BY column_id';
v_ColNames := NULL;
OPEN c_TabCol FOR v_Sql_TabCol;
Loop
FETCH c_TabCol INTO rc_TabCol; Exit WHEN c_TabCol%NOTFOUND:
v_ColNames := v_ColNames || ',' || rc_TabCol.COLUMN_NAME;
End Loop;
CLOSE c_TabCol;
v_Sql := 'INSERT INTO ' || p_AudTableName || '(HIST_DTTM, ' || v_ColNames || ' )'
|| ' SELECT systimestamp, ' || v_ColNames || ' FROM ' || p_TableName
|| ' WHEN ROWID = chartorowid(' || CHR(39) || p_RowId || CHR(39) || ')';
EXECUTE IMMEDIATE v_Sql;
COMMIT;
END;
(charmingholidays-yyz) -
I am trying to write a trigger which will update a date col after every insert////
CREATE OR REPLACE TRIGGER PS1.XX_CDATE
AFTER INSERT ON ps1.COMMNPLANBUDGET
REFERENCING OLD AS old NEW AS new
FOR EACH ROW
declare PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
update ps1.COMMNPLANBUDGET set CREATION_DATE=sysdate where PROJECTID = :new.PROJECTID;
commit;
END XX_CDATE;
For the same i have written the above code, it created successfully but when i am inserting a record the date col is not getting updated. Please let me know where i have done wrong. Thanks in advanceHello
You should not use autonomous transactions in a trigger. Do not do it, and if anyone tells you to use autonomous transactions in a trigger to avoid mutating table exceptiosn, you should instruct them to put their hands in a toaster, switch it on maximum and insist they keep them there until the timer reaches zero.
Anyway, if the primary key on this table is project ID, you don't need to go to these lengths. You can simply
CREATE OR REPLACE TRIGGER PS1.XX_CDATE
BEFORE INSERT ON ps1.COMMNPLANBUDGET
REFERENCING OLD AS old NEW AS new
FOR EACH ROW
BEGIN
:NEW.creation_date := sysdate;
END XX_CDATE;If project_id is not the primary key, why would you update the creation date for all rows attached to the project id?
David
Edited by: Bravid on Sep 22, 2011 9:29 AM
Oops, after reading Karthik's post, I realised I left the AFTER insert in the trigger spec. Updated it to BEFORE. -
Dears,
In after insert trigger implementation if the base table failed due to some errors.
Is it possible to still have records inserted in the log table inside the trigger
Thanks
Janani.CWhat you want is to write log records to a table, regardless of whether the transaction they're logging fails. This would make sense for inevstigating errors,e tc. This is the only time when it is acceptable to use autonomous transactions.
Encapsulate your logguing code in a separate procedure which has the {font:courier new}PRAGMA autonomous_transaction{font} in its declaration, and include a commit. Such a procedure works in its own separate tranasction - a separate session in fact - and write the log record without affecting the broader transaction. [url http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1515]Find out more.
Cheers, APC
P.S. I agree with Hoek that you should investigate teh LOG ERRORS INTO functionality, as it can be very useful, especially with bulk processes. However, it can only store information directly relating to the rejected records, which might not be sufficient for your purposes. -
After Insert Trigger - IF-THEN-ELSE
Is it possible to put an if-then-else statement in an after insert trigger with an update to a second table?
CREATE OR REPLACE trigger bev_trg
after insert
on bev
for each row
DECLARE
MEINS VARCHAR2(3);
SPART VARCHAR2(2);
FKIMG NUMBER(22);
SHKZG CHAR(1);
BEGIN
insert into bev2
(vbeln,
posnr)
values
(:new.vbeln,
:new.posnr
IF FKIMG = '10' and MEINS = 'EA'
THEN
update bev2 set bwsie = (fkimg * '12.17') ;
ELSIF
FKIMG = '12' and MEINS = 'EA'
THEN
update bev2 set bwsie = (fkimg * '19.02');
ELSIF
SHKZG = 'X'
THEN
update bev2 set bwsie = (fkimg * '-1');
ELSE
update bev2 set bwsie = '0' ;
END IF;
update bev2 set bwfkimg = (fkimg * '-1') where SHKZG = 'X';
end;
This does not do the updates.
Thanks
BevMy original problem is this: I need to create a table
derived from data in another table
and change it to be the conditional data in the update statements.
create table bev(
VBELN VARCHAR2(10),
POSNR VARCHAR2(6),
MEINS VARCHAR2(3),
SPART VARCHAR2(2),
FKIMG NUMBER(22),
SHKZG CHAR(1),
BWSIE NUMBER(9,2),
BWFKIMG NUMBER(22)
update bev set bwsie = (fkimg * '12.17') where SPART = '10' and meins = 'EA' ;
update bev set bwsie = (fkimg * '19.02') where SPART = '12' and meins = 'EA';
update bev set bwsie = (fkimg * '27.39') where SPART = '15' and meins = 'EA';
update bev set bwsie = (fkimg * '48.69') where SPART = '20' and meins = 'EA';
update bev set bwsie = (fkimg * '109.56') where SPART = '30' and meins = 'EA';
update bev set bwsie = '0' where meins = 'EA' and SPART not in('10','12','15','20','30');
update bev set bwsie = (fkimg * '-1') where SHKZG = 'X';
update bev set bwfkimg = (fkimg * '-1') where SHKZG = 'X';
This did not produce the required results so I thought I would try
creating a second table
and using a trigger with if-then-else to update it.
Can't use the trigger on the
original table because it mutates.
create table bev2(
VBELN VARCHAR2(10),
POSNR VARCHAR2(6),
BWSIE NUMBER(9,2),
BWFKIMG NUMBER(22)
insert into bev select vbeln, posnr, meins, spart, fkimg , shkzg, '', ''
from [email protected]
where vbeln = '0090043834' and posnr = '000011'
insert into bev select vbeln, posnr, meins, spart, fkimg , shkzg, '', ''
from [email protected]
where vbeln = '0090043833' and posnr = '000011'
CREATE OR REPLACE trigger bev_trg
after insert
on bev
for each row
DECLARE
MEINS VARCHAR2(3);
SPART VARCHAR2(2);
FKIMG NUMBER(22);
BEGIN
insert into bev2
(vbeln,
posnr,
fkimg
values
(:new.vbeln,
:new.posnr,
:new.fkimg
IF :new.FKIMG = '10' and :new.MEINS = 'EA'
THEN
update bev2 set bwsie = (:new.fkimg * '12.17') ;
ELSIF
:new.FKIMG = '12' and :new.MEINS = 'EA'
THEN
update bev2 set bwsie = (:new.fkimg * '19.02');
ELSIF
:new.FKIMG = '15' and :new.MEINS = 'EA'
THEN
update bev2 set bwsie = (:new.fkimg * '27.39');
ELSIF
:new.FKIMG = '20' and :new.MEINS = 'EA'
THEN
update bev2 set bwsie = (:new.fkimg * '48.69');
ELSIF
:new.FKIMG = '30' and :new.MEINS = 'EA'
THEN
update bev2 set bwsie = (:new.fkimg * '109.56');
ELSIF
SHKZG = 'X'
THEN
update bev2 set bwsie = (:new.fkimg * '-1');
ELSE
update bev2 set bwsie = '0' ;
END IF;
update bev2 set bwfkimg = (:new.fkimg * '-1') where SHKZG = 'X';
end; -
Hi All,
Can I have an after insert trigger on a table wherein the execution is also on the same table?
It's like 10 columns in the table A.
During a new row insertion, except one specific column(say 'J'), remaining all getting data.
Now 'after insert', need to update the data of the column J based on one inserted value for column say ID.
Code goes like below:
CREATE OR REPLACE TRIGGER UPDATE_J
AFTER INSERT ON A REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
begin
if :new.ID = 'N%' then
:new.J:= 'N';
else
:new.J:= 'M';
end if;
end;
Below is the error when I tried to execute that.
ORA-04091: table string.string is mutating, trigger/function may not see it
Cause: A trigger (or a user defined plsql function that is referenced in this statement) attempted to look at (or modify) a table that was in the middle of being modified by the statement which fired it.
Action: Rewrite the trigger (or function) so it does not read that table.
Any idea to resolve?
Regards,
Seetharaman.Hi,
The docs say
Restrictions on AFTER
An AFTER row trigger or AFTER row section of a compound trigger can only read but not write into the :OLD or :NEW fields. When faced with problems like this, it is always a good thing to consult the documentation.
Regards
Peter
Maybe you are looking for
-
Hi All, I have an issue that when you do free of charge demo goods how can we track wheather customer has return the goods or not. Thanks Arun
-
My Wifi on my iPod touch does not work.
It says that I have entered the right password as the lock symbol doesn't appear after I type it in. Then it say's "Invalid Argument" or sometimes it appears like it is getting into the internet and then the words "Cannot Connect to....". How do I co
-
According to my Creative Cloud home PS is installed and up to date, but there are no PS files on my hard drive. So I can't launch, uninstall or reinstall PS. Also having trouble downloading AI. I just updated CC software. I have MacBook Pro with 10.7
-
How to install,configure and work with omniportlets
Hi, What are the steps i need follow to install and work with omniportlets. What are the softwares in need install. Please give required steps. I downloaded. 1.PDK-Java software, PortalTools (OmniPortlet & Web Clipping), and common libraries 2.Downlo
-
Hi, we are running the finincials on 10.7 NCA and plan on upgrading to 11i. Is it possible to upgrade to 11i with only AP, FA and PO and NOT having the GL module? This is because we already have GL from another application which is our main GL and wa