ORA-04092: cannot COMMIT in a trigger - Please advise on solution

Hi guys,
I know this error has been explained in the forum before and I understand where the error comes from, but I need expert's opinion to make the trigger works.
Here is the actual situation:
Table A has a trigger on after insert, and BASED ON THE LAST ROW inserted (only this data is subject to the trigger's actions) does the following:
1. MERGE the data (last row from the source table=A) with the data from the table destination=B. This data is specific to an employee;
2. Open a cursor that goes through all the ancestors of the employee (I have an employees hierarchy) and MERGE the same data (but for ancestors) with the table destination;
To be more specific :
EmpID LOB Day Status
12 1007 29 Solved
EmpID has ancestors 24 and 95. Therefore in the destination table I will have to do:
1. Merge data for EmpID 12;
2. Merge data for EmpID 24, 95:
EmpID LOB Day Status
24 1007 29 Just S (this is the status for ancestors)
95 1007 29 Just S
Steps 1 and 2 are inside a PL/SQL procedure that works fine by itself, but not within the trigger (since there are many transactions on the destination table). These 2 steps are required because for EmpID 12 I set a status and for the ancestors I set up a different status (this was the only way I could think of).
Can someone give me a hint how should I handle this situation ?
Thank you,
John

Try this
create or replace procedure SEQ
is
pragma AUTONOMOUS_TRANSACTION;
BEGIN
EXECUTE IMMEDIATE 'create sequence ' || V_PROD ||
' minvalue 1 maxvalue 999999 start with 1';
END;
CREATE OR REPLACE TRIGGER TRG_GEN_SEQUENCES
BEFORE INSERT on MASTER_TABLE
FOR EACH ROW
DECLARE
V_PROD VARCHAR2(5);
N_ID NUMBER := 0;
CT NUMBER := 0;
ERR_MSG VARCHAR2(2000);
BEGIN
-- Retrieve the ID e of the last inserted row which is 100 by default
-- set the default client_id value with nextvalue of sequence prod_IDS
IF :NEW.ID = 100 THEN
V_PROD := :NEW.PROD;
SELECT PROD_IDS.NEXTVAL INTO N_ID FROM DUAL;
:NEW.ID := N_ID;
END IF;
BEGIN
SELECT COUNT(*)
INTO CT
FROM USER_SEQUENCES US
WHERE UPPER(US.SEQUENCE_NAME) = UPPER(V_PROD);
IF CT = 0 THEN
-- create the sequence with name of V_PROD if doesn't exist
INSERT INTO CDR_SQL_ERR
(DB_OBJ, ERR_MSG, PROC_DATE)
VALUES
('TRG_GEN_SEQUENCES',
V_PROD || ' sequence will be created ', SYSDATE);
--EXECUTE IMMEDIATE 'create sequence ' || V_PROD ||
---' minvalue 1 maxvalue 999999 start with 1';
begin
SEQ;
end;
ELSE
INSERT INTO CDR_SQL_ERR
(DB_OBJ, ERR_MSG, PROC_DATE)
VALUES
('TRG_GEN_SEQUENCES',
V_PROD || ' sequence alreday exist',
SYSDATE);
END IF;
EXCEPTION
WHEN OTHERS THEN
ERR_MSG := TO_CHAR(SQLERRM) || ' ';
INSERT INTO SQL_ERR
(DB_OBJ, ERR_MSG, PROC_DATE)
VALUES
('TRG_GEN_SEQUENCES', ERR_MSG || SEQ_DDL, SYSDATE);
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
ERR_MSG := TO_CHAR(SQLERRM) || ' ';
INSERT INTO SQL_ERR
(DB_OBJ, ERR_MSG, PROC_DATE)
VALUES
('TRG_GEN_SEQUENCES', ERR_MSG || SEQ_DDL, SYSDATE);
COMMIT;
END;

Similar Messages

  • SQL Error: ORA-04092: cannot COMMIT in a trigger

    Trying to drop the table inside the trigger but i'm unable to do it.
    SQL Error: ORA-04092: cannot COMMIT in a trigger
    I need to drop the table based on the some condition say condition is the archive table with more than millions of records which is of no use so i plan to drop the table.
    I will be inserting the the unwanted table to mytable ,mytable which is having the trigger will fire to drop the table.
    I need this to be done on automatic basis so i have chosen trigger.
    is there anyway of automatic other than trigger in this case.

    933663 wrote:
    Trying to drop the table inside the trigger but i'm unable to do it.
    SQL Error: ORA-04092: cannot COMMIT in a trigger
    I need to drop the table based on the some condition say condition is the archive table with more than millions of records which is of no use so i plan to drop the table.
    I will be inserting the the unwanted table to mytable ,mytable which is having the trigger will fire to drop the table.
    I need this to be done on automatic basis so i have chosen trigger.
    is there anyway of automatic other than trigger in this case.You can't COMMIT inside a trigger. Oracle issue an auto COMMIT before and after the execution of DDL. So you can't use DDL in trigger. You may get suggestion to use AUTONOMOUS_TRANSACTION to perform COMMIT within tirgger. But dont do that. Its wrong idea.
    I will suggest you look back into your requirement and see what exactly you want. You could schedule a job that runs on a daily basis that will pick up the object details from your table and drop them accordingly.

  • I need to remove an AOL email account that is not attached to my Apple ID.  This is on an iPAD.  It is not showing in Accounts.  However, I cannot delete the mailbox,. Please advise

    I need to remove an AOL email account that is not attached to my Apple ID.
    I am receiving email and I cannot delete the mailbox. Please advise.
    the account is not viewable in settings.

    I am assuming that this mail is coming into the Mail App, not another third party app, correct?
    Is the AOL account showing up as its own mailbox in the mail app? (e.g. I see "All inboxes", "iCloud", and a third mailbox that is my second email address.)
    Every "mailbox" except the "all inboxes" are going to be in the settings under mail, Contacts and calendars.
    If the mail is coming into a mailbox that isnt the AOL mailbox, then it sounds like you have your AOL mail being forwarded to another email adress.

  • Both in safari and Facebook app. Likewise, can't see any Facebook contact pictures on contacts app. my softwar is up to date. my Facebook app is updated. please advise any solution to this. When you view it from safari, no pictures are shown and it looks

    both in safari and facebook app. Likewise, can't see any facebook contact pictures on contacts app. my sofware is up to date. my facebook app is updated. please advise any solution to this. When you view it from safari, no pictures are shown and it looks like html script texts. In facebook app, there are texts but no no images shown. thanks.
    iPad, iOS 6.1.3

    Where did you get the device?  Is it possible that it has an IT policy on the device blocking Facebook and/or Facebook options?  Look in Options >Security Options >General Settings (actual menu paths vary with OS version) and see if there is any reference to IT policy.
    1. Please thank those who help you by clicking the "Like" button at the bottom of the post that helped you.
    2. If your issue has been solved, please resolve it by marking the post "Solution?" which solved it for you!

  • Cannot COMMIT in a trigger

    I'm getting this error in an After Insert trigger. This trigger is calling a stored procedure which is trying to reindex using "alter index myindex rebuild". This index is on the same table as the trigger.
    Also, where and how can I find information on errors returned by Oracle..
    Thanks in advance, Newbee Jerry
    null

    Hi Jerry , you can't put commit on triggers because the trigger will be part of one Transaction and this transaction won't finish until every triggers are finished. If you put a commit in one trigger you are forcing a "end of transaction " and this is not correct because you don't know if the transaction realy termineted. With this concept you can't do anything that has a commit in any trigger .
    See you ,
    Lourival

  • Iphone4 user, I  cannot hear incoming calls/text, please advise.

    I cannot hear incoming calls/text,  however, I am able to make calls/text.
    I did the sounds check (where it needs to be tested, and it works)
    Please advise.

    When you toggle the switch it will display an icon of a bell either with a line through it or not. You can double check this by looking at the link below:
    http://support.apple.com/kb/TA38625

  • I have a Mac osx 10.5.8 I HAD a Firefox browser but got sucked in by an update offer and now I have no Firefox browser and cannot get it back. Please advise.

    I have a mac powerbook G4 OSX 10.5.8 I USED to have a Firefox browser, but I got sucked in by an invitation to update, didn't realize that the circle with a line through it meant, "don't try to put this in your computer" but it must mean something like that because even tho I later tried to load a different update for a Firefox browser that said for mac osx10.5 or later, and that came up with a circle with a line through it too. How do I find the Firefox version that is compatible with my laptop? The old one was working just fine until I tried the update!!! Please advise.

    P.S. '''For Mac OS X 10.5 users with an Intel Mac''', the latest version of Firefox that will work is Firefox 16. Link: [https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/16.0.2/mac/en-US/Firefox%2016.0.2.dmg Firefox 16 (US English)]
    Related article: [[Firefox no longer works with Mac OS X 10.5]]

  • When I try to go to icloud I get 'script problem' and cannot enter. Could someone please advise me what to try. Thanks.

    When I try to go to ilcoud I get 'script problem' and can't enter. Please advise what I should try. Thanks.

    I use e-trade and a couple of times, years back, I found them behind the Java updates.
    So, now I install new Java platforms on my backup disk and test the streaming data on that first because I know it will be over-written that evening with my nightly backup.
    Of course, since I began doing that there hasn't been a problem. Do the same with printer driver updates.
    Anyway, call ScottTrade and howl! Tell them how many Macs are out there and why aren't they in Apple Developers Program?

  • Laptop asus cannot download ADOBE FLASH. Please advise!

    Good day to you. I have an ASUS LAPTOP i5 and did try the help steps 1.2.3. but still it does not let me install ADOBE FLASH.
    PLEASE ADVISE!!

    Hello,
    What does "but still does not let me install" mean? Read Before Posting: How To Get A Useful Answer To Your Question and provide the required information so that we may be able to assist you.
    Thank you.
    Maria

  • I am unable to connect to the internet via WiFi connection.  My iphone works just fine.  Please advise possible solutions.

    I have an iPad on v5.01.  I am unable to use my wifi network to connect to the internet.  My wife's iPad works fine.  Please advise any potential solutions.

    Have you checked to see if your WiFi router needs to have your iPad's MAC address specifically permitted to use WiFi?  Some WiFi routers have a section in the settings called "Access List", possibly under "Security".
    You can find the MAC address in Settings > General > About > Wi-Fi Address

  • Please advise correct solution for Search help

    Hi ,
    i want to develop a webdynpro application( in ECC 6) which takes data from 4.6C . So i have to provide my own search helps to certain fields ( like material number) .
    As i am very new to webdynpro i planed to make search helps in ECC and using search help exit and RFC ( fetching data from 4.6c) fill data to these search helps and assign this to webdynpro fields. Is it make a -ve effect on perfomance? is there any alternative way to do this ? please advise.
    Regards,
    Ratheesh BS

    >
    Ratheesh Bhaskaran wrote:
    > Hi ,
    > Can you please explain this 'There is a BAPI that doesn't remote search helps generically' .
    > Regards,
    > Ratheesh BS
    Well that should have read - 'There is a BAPI that does remote search helps generically'.  That makes more sense.  The BAPI name is BAPI_HELPVALUES_GET.

  • HT1688 my apple id has been disabled and I have not been able to get it back up. I cannot update apps etc. Please advise

    Each time I try to update applications etc. I get a message on my iphone that my Apple ID is disabled. Please help! Thank you.

    Nenita1437 wrote:
    ...I get a message on my iphone that my Apple ID is disabled. ..
    If disabled for Security Reasons... See here  http://support.apple.com/kb/TS2446
    If not for Security reasons...
    To Contact iTunes Customer Service and request assistance
         Use this Link  >  Apple  Support  iTunes Store  Contact

  • Airbook cannot see external optical drive, Please advise

    Hi guys, I have a Airbook, everything on it works, It picks up my external HDD but not my external optical drive. I am sure the
    optical drive is working. Could you please provide assistance as to how I should best troubleshoot this issue?
    Thank you

    Do you have the checkbox checked in Finder Preferences to show "CDs, DVDs, and iPods" on the desktop?

  • HT201303 i cannot remeber my security answers. please advise how i can sort this out, to purchase more items

    help me to reset my security answers, as i have forgotten them

    Read here:
    http://support.apple.com/kb/HT5665

  • As my screen only shows 2/3rds and cannot see right 1/3, please advise how to fix

    My screen when I opened this morning on Firefox only showed 2/3rds of the screen and I couldn't see the right 1/3rd.
    Can this be fixed?
    I opened up Windows okay

    This issue can be caused by the Babylon Toolbar 1.1.8 extension
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

Maybe you are looking for

  • Imessage and other Issues with 3rd Gen iPad

    Hi there, just got a 3rd Gen iPad for the mrs and so far it's been great. However, several rather annoying issues have developed and I can't seem to find the right trouble shooting for it, so I thought I'd try here. So here they are: iMessage & facet

  • How do i upload the photo stream pictures on my iphone to my pc

    hi i have successfully uploaded some photos from my Iphone to my pc but find that the photo stream pictures were not included is there a way to upload this batch ?

  • More....! Aperture 3.0.2 bugs...??

    Hi... Since the Aperture 3.0.2.update I have experienced quite a few frustrating faults. Prior to this update... from what everyone else has experienced, I had no glitches at all. 1. As I posted elsewhere here, I had the Teal Green effect.. where a n

  • Upgrade Sharepoint 2010 SQL Reporting Services from 2008 R2 to 2014

    I'm about to do the upgrade of SharePoint 2010 Reporting Services from 2008 R2 to 2014.  The instructions say it can be done "in-place" with no downtime.  I've seen this article: http://whitepages.unlimitedviz.com/2012/03/upgrading-sql-server-reporti

  • Deleted emails show up again in spotlight

    When I type a few characters in spotlight, very old emails show up. I clicked it and it opened the mail.app and the email is still there in a freestanding box. I am unable to delete it however.  I have tried several things. rebuilding mailbox. deleti