Inserting Records In A Trigger
Greetings,
I have a table which has a trigger that calls a stored procedure
to insert additional records into the same table. One trigger
is set after each row for insert/update/delete . The before
trigger calls another proc to populate a global pl/sql table for
the insert in the after trigger. All is okay except for the
insert of the additional record. The original record which
invoked the trigger sequence is sucessfully created, but the
addition record that the triggers create does not.
I Encounter an error on the insert withing a proc called by the
after trigger:
-4091: ORA-04091: table SPINTEK.ST_LGEN_RELATION is mutating,
trigger/function may not see it.
How can I create a record in a table via an after trigger while
another record is also being inserted?
Cheers and Happy Holidays.
Marcel Sammut
[email protected]
You can't.
Just think about it for a minute - if you have a trigger that
fires after an INSERT, and that trigger attempts to perform
another INSERT on the same table, then when what would prevent
an infinite cascade of INSERTs from occurring?
That's why you can't perform DML on a table in (or from) a
trigger on the same table.
Similar Messages
-
[Solved] Unable to insert records, trigger is showing mutating error
Friends,
I created a procedure
===>>
SQL> CREATE OR REPLACE PROCEDURE PO_RECEIVINGS_ASSETS_TR_P
2 IS
3 CURSOR CUR_LAST_DAY_RCV IS
4 SELECT * FROM PO_RECEIVINGS_INSTANT_V WHERE TRANSACTION_ID = (SELECT MAX(TRANSACTION_ID) FROM PO_RECEIVINGS_INSTANT_V);
5 BEGIN
6 FOR REC_LAST_DAY_RCV IN CUR_LAST_DAY_RCV
7 LOOP
8 FOR i IN 1 .. REC_LAST_DAY_RCV.QUANTITY
9 LOOP
10 INSERT INTO ND_TEST VALUES(REC_LAST_DAY_RCV.TRANSACTION_ID, REC_LAST_DAY_RCV.CREATION_DATE, REC_LAST_DAY_RCV.QUANTITY,
11 REC_LAST_DAY_RCV.PO_LINE_ID);
12 END LOOP;
13 END LOOP;
14 END;
15 /
Procedure created.
<<===
then created a trigger to insert record in ND_TEST when a record is inserted in RCV_TRANSACTIONS_ND
===>>
SQL> CREATE OR REPLACE TRIGGER PO_RECEIVINGS_INTO_ASSETS_TR
2 AFTER INSERT ON RCV_TRANSACTIONS_ND
3 FOR EACH ROW
4 BEGIN
5 IF :NEW.TRANSACTION_TYPE = 'ACCEPT' THEN
6 PO_RECEIVINGS_ASSETS_TR_P;
7 END IF;
8 END;
9 /
Trigger created.
<<===
when I try to insert record in RCV_TRANSACTIONS_ND, I get below lines.
===>>
SQL> INSERT INTO RCV_TRANSACTIONS_ND (TRANSACTION_ID,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,
2 CREATED_BY,TRANSACTION_TYPE,TRANSACTION_DATE, QUANTITY, UNIT_OF_MEASURE, SHIPMENT_HEADER_ID,
3 SHIPMENT_LINE_ID,USER_ENTERED_FLAG, PO_HEADER_ID, PO_LINE_ID)
4 VALUES(1001001,SYSDATE,3572,SYSDATE,3572,'ACCEPT',SYSDATE,1,'Nos',199999,199099,'Y',133032,1679
29);
INSERT INTO RCV_TRANSACTIONS_ND (TRANSACTION_ID,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,
ERROR at line 1:
ORA-04091: table RCV_TRANSACTIONS_ND is mutating, trigger/function may not
see it
ORA-06512: at "PO_RECEIVINGS_ASSETS_TR_P", line 4
ORA-06512: at "PO_RECEIVINGS_ASSETS_TR_P", line 6
ORA-06512: at "PO_RECEIVINGS_INTO_ASSETS_TR", line 3
ORA-04088: error during execution of trigger
'PO_RECEIVINGS_INTO_ASSETS_TR'
<<===
Using Database 9i.Well, I tried to solve it and it worked.
SQL> CREATE OR REPLACE PROCEDURE PO_RECEIVINGS_ASSETS_TR_P(VAL1 IN NUMBER, VAL2 IN DATE, VAL3 IN NUMBER, VAL4 IN NUMBER)
2 IS
3 BEGIN
4 FOR i IN 1 .. VAL3
5 LOOP
6 INSERT INTO ND_TEST VALUES(VAL1, VAL2, VAL3, VAL4);
7 END LOOP;
8 END;
9 /
Procedure created.
===
SQL> CREATE OR REPLACE TRIGGER PO_RECEIVINGS_INTO_ASSETS_TR
2 AFTER INSERT ON RCV_TRANSACTIONS_ND
3 FOR EACH ROW
4 BEGIN
5 IF :NEW.TRANSACTION_TYPE = 'ACCEPT' THEN
6 PO_RECEIVINGS_ASSETS_TR_P(:NEW.TRANSACTION_ID, :NEW.CREATION_DATE, :NEW.QUANTITY, :NEW.PO_LINE_ID);
7 END IF;
8 END;
9 /
Trigger created.
===
SQL> INSERT INTO RCV_TRANSACTIONS_ND (TRANSACTION_ID,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,
2 CREATED_BY,TRANSACTION_TYPE,TRANSACTION_DATE, QUANTITY, UNIT_OF_MEASURE, SHIPMENT_HEADER_ID,
3 SHIPMENT_LINE_ID,USER_ENTERED_FLAG, PO_HEADER_ID, PO_LINE_ID)
4 VALUES(1001001,SYSDATE,3572,SYSDATE,3572,'ACCEPT',SYSDATE,1,'Nos',199999,199099,'Y',133032,1679
29);
1 row created.
===
Thanks everyone -
Retrieving latest updated or inserted records without using a trigger
I have to retrieve the latest updated/inserted records from a set of database tables. Say, if 'n' sets of different records have been updated or inserted into one or more different database tables then all the 'n' records of data should be retrieved using a java code without using a trigger.
helpmeplz wrote:
Thanks for your reply.
But I don't know when or from where or what kind of data gets inserted/updated into the tables. I need a listener or a component which can handle events occured on the particular set of database tables, and get the event data. the java code should get the updated/inserted rows that have been inserted into a set of database tables by a third party.
Please lemme know how I can do this.Realistically you can't.
If and only if the tables have a modification timestamp then you could use that. Every table would need it.
Other than that the only othe possibility would require that you keep an entire copy of each table in the memory, poll at a set interval and then do an entire comparison for each table. For very small data volumes (on the target tables) that is practical. For larger volumes it isn't. -
How to use array list with fixed values to insert record in trigger
I have a list of number 1,30,40,45,60 . These numbers are not being changed so I don't need to keep in a table. So have to create a after insert trigger for
As
Begin
@list = 1,30,40,45,60 // Array value
for i=1 to @list.count
Insert into mappingtable(arrayvalue,itemcode) values (list[i],Inserted.Itemcode)
Next
End
Please can you help with a code
Regards
Pol
polachanBe careful what you assume - rarely are lists of values like this truly static. One thing to keep in mind that arrays in sql server are tables. So, one example is:
set nocount on;
/* represents the virtual inserted table in your trigger */
declare @inserted table (itemcode char(4));
insert @inserted (itemcode) values ('ABCD'), ('JJKL');
select * from @inserted;
select * from @inserted cross join (values (1), (30), (40), (45), (60)) as arrayx(value); -
How can i display recent update/delete/insert records in form
Hai !!!!
i am new for forms,.......any body tell me, how can i display recent no of records updated or no of records deleted or no of records are inserted in a form. these records count are display in display items....give me detail explination......
Subbu.....the easiest way is copy and paste the oracle-forms example from the OU.
You need form-level-trigger ON-ERROR + ON-MESSAGE, POST-INSERT, POST-UPDATE, POST-DELETE, three global variables and a procedure:
ON-ERROR
handle_message( error_code, 'ERROR: ' || ERROR_TYPE || '-' || TO_CHAR(ERROR_CODE) ||': '|| ERROR_TEXT );
ON-MESSAGE
handle_message( message_code, MESSAGE_TYPE || '-' || TO_CHAR(MESSAGE_CODE) || ': ' || MESSAGE_TEXT );
PROCEDURE handle_message( message_number IN NUMBER, message_line IN VARCHAR2 ) IS
BEGIN
IF message_number IN ( 40400, 40406, 40407 )
THEN
DEFAULT_VALUE( '0', 'GLOBAL.insert' );
DEFAULT_VALUE( '0', 'GLOBAL.update' );
DEFAULT_VALUE( '0', 'GLOBAL.delete' );
MESSAGE('Save Ok: ' ||
:GLOBAL.insert || ' records inserted, ' ||
:GLOBAL.update || ' records updated, ' ||
:GLOBAL.delete || ' records deleted !!!' );
ERASE('GLOBAL.insert');
ERASE('GLOBAL.update');
ERASE('GLOBAL.delete');
ELSE
MESSAGE(message_line );
END IF;
END;
POST-INSERT
DEFAULT_VALUE('0', 'GLOBAL.insert');
:GLOBAL.insert := TO_CHAR( TO_NUMBER( :GLOBAL.insert ) + 1 );
POST-UPDATE
DEFAULT_VALUE('0', 'GLOBAL.update');
:GLOBAL.update := TO_CHAR( TO_NUMBER( :GLOBAL.update ) + 1 );
POST-DELETE
DEFAULT_VALUE('0', 'GLOBAL.delete');
:GLOBAL.delete := TO_CHAR( TO_NUMBER( :GLOBAL.delete ) + 1 );try it
Gerd -
Unable to insert record in table
Hi,
I want to insert record in database table, but when I execute insert command(at When List changed trigger) as select from query and issue commit, the form trying to insert record from datablock which is obviously having empty items, how can I commit at database level not at form level.
*******************Below the SQL Statement issued by Form******************
INSERT INTO BILL_OF_MATERIALS_TABLE(PROJECTNO,GROUP_,ITEM,STATUS,QUANTITY,UNIT_PRICE,REASON_FOR_CHANGE,REMARKS,AWARD_COPY,LOCKED,VO_COPY) VALUES (:1,:2,:3,:4,:5,:6,:7,EMPTY_CLOB(),:9,:10,:11) RETURNING ROWID,PROJECTNO,GROUP_,ITEM,STATUS,QUANTITY,UNIT_PRICE,REASON_FOR_CHANGE,REMARKS,AWARD_COPY,LOCKED,VO_COPY INTO :12,:13,:14,:15,:16,:17,:18,:19,:20,:21,:22,:23
***************Error Raised by Form********
ORA-01400: cannot insert NULL into ("CAPEX"."BILL_OF_MATERIALS_TABLE"."ITEM")Remember that when you write "commit;" within your forms code then Forms interprets it as a commit_form statement. That's why the form-level commit is launched as you mentionned.
So if you want to make a database commit then I think that you should create a stored procedure which makes the insert , and you call this stored procedure within your forms code.
Try it. -
ORA-03113 error occurs when trying to insert record using procedure
I have a Database Block whose DML Data Target Type is Procedure. I have given the Insert Procedure Name, Insert Procedure Arguments and Insert Procedure ResultSet Columns. The procedure which is used to insert record into the table, resides in the database. The procedure for insert takes Table of records as argument. I am getting FRM-40735: INSERT-PROCEDURE trigger raised unhandled exception ORA-03113).
This exception does not occur if the Procedure is place under Program Units. But, I want the procedure to be under Database Block. I am working on Oracle Forms 6i.
Please help me out in resolving this.Hello,
I think you should call the support for this kind of error.
Francois -
Inserting records into a table with all caps
Hello
I have a procedure that inserts records into a table. How do I ensure that the text values inserted are recorded all capital letters into the table?
Thanks.You can use UPPER(..) function in your insert statement, so that values are converted to UPPER, before insert.
If you want to check at table level, you can achieve that by writting a before insert trigger and in that trigger check
IF UPPER(:new.<col>) != :new.<col> THEN
RAISE_APPLICATION_ERROR(-20101,'Error: Not all values are in upper case')
END IF; -
Inserting Record In same table through triggers.
Hi,
I've a table cus_mst ( cus_div_cd vachar2(1), cus_cd varchar2(5), cus_nm varchar2(100) )
Records are inserted in this table through forms ...
We need to automatically insert a record with a diff div_cd for any record inserted in the table .
If div_cd 'I' is entered automatically a record with div cd 'S' with other coulmns having same values should get inserted .
In case div_cd is 'S' then record with div_cd 'I' should get created.
Eg : If in insert ( 'S', 'A0001', 'ABC COmpany' ); another record with values ( 'I', 'A0001', 'ABC Comapny' ) gets created;
One way to do is to insert records in a view ( on the table ) and use instead of trigger to insert the corresponding record. But that is not possible as development team has to change form and use view instead of table.
Have tried doing it by populating a collection in-each-row trigger and then using statment level trigger to insert from the collection. But this leads to recursive error.
Would be great to get more insights into this..
thanks
cheers
JaaniHi,
Within the following script you need to make adjustments according to your needs about the columns you need to test. But this might help you.
Sorry for the layout. But I was not able to adjust it in a short time.
drop table ad_test
create table ad_test ( col1 varchar2(1), col2 varchar2(5), col3 varchar2(100) )
create or replace package ad_test_pkg is
procedure initialize_postpone ;
procedure postpone_record( r_atst in ad_test%rowtype ) ;
procedure handle_postponed_records ;
end ad_test_pkg ;
create or replace package body ad_test_pkg is
type type_atst is table of ad_test%rowtype index by binary_integer ;
t_atst type_atst ;
procedure initialize_postpone is
begin
t_atst.delete ;
end initialize_postpone ;
procedure postpone_record( r_atst in ad_test%rowtype ) is
begin
t_atst(t_atst.count) := r_atst ;
end postpone_record ;
procedure handle_postponed_records is
cursor c_test( cpiv_col1 in ad_test.col1%type ) is
select 'x'
from ad_test
where col1 = cpiv_col1
r_test c_test%rowtype ;
r_atst ad_test%rowtype ;
begin
for i in t_atst.first .. t_atst.last
loop
r_atst := t_atst(i) ;
if r_atst.col1 = 'I'
then
r_atst.col1 := 'S' ;
else
r_atst.col1 := 'I' ;
end if ;
open c_test( cpiv_col1 => r_atst.col1 ) ;
fetch c_test into r_test ;
if c_test%found
then
close c_test ;
else
close c_test ;
insert into ad_test
( col1
, col2
, col3
) values
( 'S'
, r_atst.col2
, r_atst.col3
end if ;
end loop ;
end handle_postponed_records ;
end ad_test_pkg ;
create or replace trigger test_ad_bis
before insert on ad_test
begin
ad_test_pkg.initialize_postpone ;
end ;
create or replace trigger test_ad_air
after insert on ad_test for each row
declare
r_atst ad_test%rowtype ;
begin
r_atst.col1 := :new.col1 ;
r_atst.col2 := :new.col2 ;
r_atst.col3 := :new.col3 ;
ad_test_pkg.postpone_record( r_atst => r_atst ) ;
end ;
create or replace trigger test_ad_ais
after insert on ad_test
begin
ad_test_pkg.handle_postponed_records ;
end ;
insert into ad_test values ( 'I', 'A0001', 'ABC COmpany') ;
select * from ad_test ;
Greets,
Ad
Edited by: loaddev on 10-nov-2010 4:47 -
Oracle forms error frm-40508: unable to insert record
Hi Everyone,
I have been having this problem for 2 weeks and I realize that I spent alot of time I couldn't get to fix the problem so I need your help.
Here is my situation. First, I installed Oracle 10g in my laptop with Oracle forms10g and Oracle forms904i. I had oracle_home folder as the top level structure then I have inside oracle folder, Oracle10g in it own folder, Oracle9i release2 in it own folder. then I created the user account "student" using the system/manager account finally I granted privilleges as follow:
GRANT ALL PRIVILLEGES
TO student
WITH ADMIN OPTION;
this was working perfecty I didn't need to grant objects privilleges such as
GRANT INSERT, UPDATE, DELETE
ON customers
TO student;
Then I created a form Application prototype and it works well I could Insert, Update and Delete but now I am creating an e-commerce application prototype I created an new account using a system/manager account as I did previously and grant all privilleges. When I try to grant object privileges the message that I receive says ORA-01919 : role 'INSERT' doesn't exist
When I run the application I am unable to insert the record through forms I get message frm-40508 Orcle error: unable to insert record.
I deinstall the Oracle and clean my laptop and did a clean installation using only Oracle Server10g and Oracle Developer10g I am getting the same message frm-40508.
Can someone please help me on this. the insert command that I am running is a simple one such as
INSERT INTO customers
VALUES( block_name.field_name, ....);
COMMIT;frm 40735:When button pressed trigger raised unhanded exceptionplease help me to solve this>
The FRM-40735 is a generic Unhandled Exception. Please post the full error message so we can better help you.
Craig B-)
If someone's response is helpful or correct, please mark it accordingly. -
I bulid trigger in tabel and check condition, if for example check_statment = X i need to delete inserted record (that mead not insert record) and when check_statment = Y then insert record in table, i try to write delete statment and rollback but there is error appear that the current record are reserved.
How i can solve it.1. Triggers cannot Issues ROLLBACK, SAVEPOINT, COMMIT statements.
2. I guess you are trying to avoid duplicate records, Create a unique index on the key(col1,col2) which you want to prevent duplicates on.
3. Or you can Add a column Flag Chr(1) to your table. While inserting you allow the records to get inserted, but based on your condition change the Flag to 'D' - deleted , 'A' -active. Build a View which the user uses for application filtering out the 'D'eleted records.
Does this look like what you are trying to do !
Ss -
Hi,
I'm sure this is a common problem, I could not find anything
relating to it in search here so...
I have a form, which I insert data into database, fine.
I then want to post the same form to paypal payment page.
I've got paypal set-up fine with hidden fields in the form
etc. However, how can I make the insert into database and then post
the form to paypal ? should I use onClick event to trigger insert
and action to post to paypal ?
using asp vb
Any advise appreciated.It'd be a 2 page process. On page 1, you submit the form and
insert record
into database. Then redirect to page 2. On page 2, you'd
submit the form on
load and post it to paypal.
Jules
http://www.charon.co.uk/charoncart
Charon Cart 3
Shopping Cart Extension for Dreamweaver MX/MX 2004 -
Plus sign or insert record button on toolbar
Hi there,
What trigger fires when insert record button or plus sign from toolbar is clicked?
ThanksThanks for answering my question.
Now I created a KEY-CREREC trigger with code
1. I have a procedure that enables some fields and go_item('block.item1')
2. create_record;
There are 2 undesirable things that are occuring
1. user queries records, clicks on plus sign, the cursor does not go to the 1st field in the block even though i say go_item(block.item1)
2. to exit without saving the record, i have to click on remove record and then exit. is there a way of exiting out of the form without clciking on remove record button
Thanks a lot -
Hi all :)
i think that i have problem in the phase of insertion ...
that's my code :
//insert
declare
i number;
begin
commit_form();
i := show_alert('VALID');
clear_form;
end;
But,when i want to update record ,i encounter this error:
frm-40508 impossible to insert record
Violation unique constraint
Any solutions ?
best regards
Edited by: 979155 on 4 janv. 2013 19:45hi,
I know there are two modes in oracle:
automatic and manual; for manual I mastery but the alternative ideas I just on consultation (using execute_query) but for the update I have not ideas ...
for the button, it is that there must be a trigger (when-button-pressed)? If yes, what it will contain code in pl / sql? -
Insert record using stored procedure
Dear all,
I want to insert record using stored procedure in form6i,
any help or suggestion will be appreciated.
regards
Kashif AliKashif,
Could you please explain what you are trying to accomplish? Inserting records into a table from Forms is as simple as executing an INSERT statement in a Forms trigger or as complicated as overriding the Forms default INSERT functionality by defining your own On-Insert trigger. Your requirements will dictate where and how you do your INSERT.
Craig...
Maybe you are looking for
-
Error in tablibs ..Any help on this please
hi, I am getting the following error when i try to run the below code .. I put all the files in corresponding folders and i am getting the following error when i run Test.jsp Error: 500 Location: /Test.jsp Internal Servlet Error: org.apache.jasper.co
-
I am having difficulty locating my library. This has just happened, after using iTunes for many years. What's up with that?
-
Draw straight lines, locked at each end?
I've got a wiring diagram that I want to add connections to, see above. I've tried using the Line Segment Tool, and the Pen; these produce the red and black lines connecting the square box at the top to the table below. However, I want to move their
-
MacBook Air OS X Lion 10.7.5 app to read digital magazine?
MacBook Air OS X Lion 10.7.5 app to read digital magazine?
-
[solved]VPLS can not activate
Hello guys, I meet a pretty strange problem. I use ME36600X to test the vpls. And i cant activate the vfi.It said "Maximum number of VFIs 0 have been configured." And the other ME3600x have no problem at all. Someone know where is the problem? The tw