How to avoid triggers from firing recursively?

We're using a packaged application on top of oracle 9i. The application makes an entry into a table whenever organization entity A charges an amount to entity B. To be able to follow the flow of these charges in both directions a corresponding entry for entity B has to be made in this table as well. Unfortunately the packaged application doesn't provide this function and we're trying to solve this issue with triggers for this table.
The logic of the trigger is as follows:
Upon insert of record A(Col1,Col2) into table Z, insert an additional record B(Col2, Col1) in table Z.
We created similar triggers to cope with update and delete events.
The syntax and logic of the triggers is fine. Upon execution the trigger raised an error saying it cannot update the table as it is being already updated by the calling DML statement.
There is workaround mentioned for this situation in the Oracle documentation using a temporary table (a row trigger writes for each record to the temporary table; at the end a statement trigger fires which copies those entries back to the original table). We've also tried this but now the problem is that those triggers fire each other iteratively thus creating an infinite loop which only stops upon hitting the cursor limit (at the moment it's 50).
Does anyone experience a similar problem and has a solution for this (short of handling it outside of the database)? Upon interest I can also post the trigger codes.

The global temporary approach works. Another alternative is to store the values in an array (PL/SQL table in a package) and then loop through the array in the after statement trigger. In any case, to handle the recursion issue, maybe this template will help you:
sql>create table t (c int);
Table created.
sql>create global temporary table gtt (c int) on commit delete rows;
Table created.
sql>create or replace package state
  2  is
  3    g_recursing  boolean := false;
  4  end;
  5  /
Package created.
sql>create or replace trigger t_trg
  2  after insert on t
  3  for each row
  4  begin
  5    if not state.g_recursing then
  6      insert into gtt values (:new.c + 1);
  7    end if;
  8  end;
  9  /
Trigger created.
sql>create or replace trigger t_trg_s
  2  after insert on t
  3  begin
  4    if not state.g_recursing then
  5      state.g_recursing := true;
  6      insert into t select * from gtt;
  7      delete from gtt;
  8      state.g_recursing := false;
  9    end if; 
10  end;
11  /
Trigger created.
sql>insert into t values (1);
1 row created.
sql>select * from t;
        C
        1
        2
2 rows selected.
sql>insert into t values (3);
1 row created.
sql>select * from t;
        C
        1
        2
        3
        4
4 rows selected.

Similar Messages

  • How to avoid timeouts from Enterprise Manager/BPEL console?

    Occasionally I want to deploy (from JDev) some BPEL processes to the AppServer.
    Surprisingly I got some errors. I found out when I re-login into
    Enterprise Manager and tried again to deploy it everything works fine.
    So it seems to me all errors occur because of a forced logout from Enterprise Manager.
    How can I avoid such situations?
    Peter

    Hi peter,
    See this forum link:
    Re: How to avoid auto-logout (=timeout) BPEL console?
    It contains your post only. See it.
    Cheers,
    Abhi...

  • How to avoid outage from db level

    Hi All,
    I'm having task as, I need to give *15 diffrent ways/ideas/scripts to avoid outage from Oracle DB level in general* within short period(3 weeks). Where we need to focus and what are the stuff, need to do to complete this.
    I guess, Outage means DB down, bcoz of this, user's can't to the db through appication. is it correct?
    1.By genetal, how the people are avoiding outage there environment?
    2.when we will get outage, I mean in which situation we will get ?
    3. I guess,we can do in parameter level. But, I dont know, what are the parameter we can use here?
    Please guide me and advice me, to complete this task.
    Thanks in advance.

    2.when we will get outage, I mean in which situation we will get ?Usually when you run out of some resource you can get partial or full outage.
    I.e. when there are too many connections - new connection will be rejected and will see it as outage. Old ones will work. It is a partial outage.
    Or when disk space is totally consumed - selects may work, updates wont.
    Or there is no virtual memory left some sessions may fail.
    Full outages are rear things - usually caused by H/W failures or environmental disasters.
    1.By genetal, how the people are avoiding outage there environment?Different ways.
    - Planning for resources according to consumption analysis and predictions.
    - By monitoring of resources and environment and taking proactive measures.
    - By establishing High Availability and Disaster Recovery solutions.
    - And finally by establishing Business Continuity plan where is is no IT at all (using pencils and papers, abacus, fingers, and brain to run business as 120 years ago).
    3. I guess,we can do in parameter level. But, I dont know, what are the parameter we can use here?Oh it easy - put the parameter WORK_ALWAYS=ON into your config file and its done!
    Seriously, there are many parameters that you can tweak depending on your planned resource usage.
    But not everything can be done by just parameters tweaking.
    See reply on #1.

  • How to avoid photoshop from changing colours of photos automatically?

    Photoshop automatically change the colour of my photos when dragged and dropped for contouring. How to avoid this?

    PS doesn't change any colors. You need to read up on color management and calibrate your system.
    Mylenium

  • How to stop events from firing

    helo..
    is there a way to stop an event from firing.. or making an effect event if it was raised..
    for example in my application.. i have a JList which has a ListSelectionListener and a PopupListener... when i right-click.. the populistener fires.. and also my selection (say i made a select-all-items) gets changed.

    Remove one if the listeners??
    /Kaj

  • How to avoid triggering of a workflow multiple times at the same time?

    Hello Workflow Gurus,
      This is the situation.
    I have a Notify requisition creator workflow. This workflow is triggered only when a PO is completely released(this Po is created with respect to a purchase req). I have implemented multiple release strategy in my PO workflow. Meaning, if a PO is created for 5 million, 4 entries are created in the release strategy(P0, P2, P3 and P4). Some approvers have authorization to approve P0 and some have authorization to release P2 etc. Before an approver can release P4, P0, P2 and P3 shuould be approved first.
    My problem is when a approver has auth to release both P3 and P4, and if he hits the SAVE button, it is completely released and  2 notify req workflows are being triggered. I use the release indicator = 'C' (completely released) to trigger thos notify req creator workflow. In this case both workflows are triggered at the same time and date. I somehow have to say if this is triggered at the same date and time, complete one workflow.
    BTW, I am not using any user exit to trigger this. This notify req creator WF is triggering event is "RELEASED'. When pO is completely released, 'RELEASED' event gets triggered which caused the notify req creator WF trigger.
    How can I accomplish this?
    Thanks
    Rachana

    Hi Rachana,
    Another way you could acheive this is to use start conditions for your workflow. You could specify that your workflow should get triggered only for release codes = XX or release strategy = XX, etc.. This way even after 1 stage of approval, when the approver clicks on SAVE, the release codes change and because there is start conditions in the workflow that would prevent another instance of the workflow from getting triggered.
    For example, in your case, I presume PO, P1, P2, etc are your release codes.
    You can have a start condition in your workflow wherein you specify that the workflow should get only triggered for release code = P2 [assuming release code P2 is always the 1st stage of approval]. So, once the approver for P2 has completed and Saved, since there is a start condition, there wouldnt be any other workflow instance started. By this way, any stages of approval wouldnt cause another workflow to initiate.
    Hope this is what you have been looking for ?
    Satish

  • How to avoid user from entering new price condition in return order

    Dear Expert
    We are facing a scenario where we make return order; the Price is copied from the invoice. And it is working perfectly. The system does not allow us to change the price.
    The issue we are facing here is that user can input new condition like discount /premium and change the net value for the return order pricing, and this will reflect in the credit note for returns.
    Is there a way to restrict the user from entering any pricing condition in the header or item conditions tab.
    although we cannot change the original price coming from invoice referenced for return order, but the user can input new price conditions as below. This must not be allowed.
    The price must come according to the Qty being referenced.
    While making the credit for returns, the user has a chance of further making changes to the net value by adding new conditions. Hence this must also be restricted for any changes.
    Thanks
    Edited by: Lakshmipathi on Jan 31, 2012 6:55 PM
    Thread Locked - Reason Cross Post

    okie .... i will tell briefly what is the problem ....
    Take a scenario wherein a user has logged into my application and he is performing a task which will put his user id and his employee id into the session. Then he opens another window by using either ctrl+n or through files->new window.
    So now a new browser will open but the session will be same ..... in this newly opened browser, user performs some operation which will remove the user id and employee id from the session .... Now if he again comes back to the first window and tries to do some operation, then a null pointer exception will be thrown saying that the employee id is null .... because he has deleted that in the newly created browser ..... to avoid this situation what can we do ???? can you please help me in this regard ??? you got my problem right !!!

  • How to avoid apps from my iPhone installed on my iPad?

    I just bought an iPad 32Gb Wi-Fi, and as soon as I activated it I got all the apps from my iPhone installed on it, including the ones that don't work on the iPad.
    I deleted them from the iPad, but everytime I sync it with my iTunes I get them back again.
    Is there a recommended way to sync both an iPhone and a iPad using the same Mac? Or how do you handle that scenario?
    Thank you
    Simone

    Hi-
    Manually managing the apps will allow you to select which you wish to install/sync.
    http://support.apple.com/kb/ht1535
    Using the Applications Tab in the iPad iTunes window will allow you to select which apps are installed.

  • How to avoid duplicates from the form

    when I'm enter MR number , all the data(Part number , Desc details) are displaying correct and then search for desc the duplicate data is displaying actually not duplicate, their MR number is different , but in the form we r showing only the Partnumber & Desc details. and its directly from the table.
    this is the code for search the desc
    DECLARE
    WERE VARCHAR2(2000);
    WERE1 VARCHAR2(1000);
    FIND VARCHAR2(30);
    BEGIN
         :GLOBAL.CODE :=:BLK_MR.SEARCH;
         GO_BLOCK('MR_SELECT_VIEW');
         --WERE :='WHERE MRD_CCNO =  '||TO_CHAR(:BLK_MR.MRNO)||' AND
    -- ITEM_DESC LIKE '''||'%'||:GLOBAL.CODE||'%'||''' ORDER BY ITEM_DESC ';
    MESSAGE(TO_CHAR(:BLK_MR.ITEM61));
    MESSAGE(TO_CHAR(:BLK_MR.ITEM61));
         WERE :='WHERE MRD_CCNO IN ( SELECT VE_CC_NO FROM VE_MASTER WHERE VE_GROUP_CODE=
    '||TO_CHAR(:BLK_MR.ITEM61)||'
    AND VE_SUBGROUP_CODE='||TO_CHAR(:BLK_MR.VE_SUBGROUP)||')
    AND ITEM_DESC LIKE '''||'%'||:GLOBAL.CODE||'%'||''' ORDER BY ITEM_DESC ';
    MESSAGE(WERE);
    MESSAGE(WERE);
         SET_BLOCK_PROPERTY('MR_SELECT_VIEW',ORDER_BY,'');
         SET_BLOCK_PROPERTY('MR_SELECT_VIEW',DEFAULT_WHERE,WERE );
    EXECUTE_QUERY;     
    END;
    how to take the distinct partno from the table, since its is directly from the table.
    b'cos its checking MR number as a where condition

    HI!
    I advise you to create one more block with data type=From clause And as Name nest select (select distinct....)... and then, make, for example on pressing the button change data type of the block:
    set_block_property(block_name, QUERY_DATA_SOURCE_TYPE, get_block_property(block_name(with from clause), QUERY_DATA_SOURCE_TYPE));
    set_block_property(block_name, QUERY_DATA_SOURCE_NAME, get_block_property(block_name(with from clause), QUERY_DATA_SOURCE_NAME));

  • Can u tell me in simple words how to delete pictures on my iPad, which I never asked to be transfered from my PC, and how to avoid it from happening next time I sync my PC to my Ipad. I am inexperienced

    what now?

    If the pictures were taken on the pad, or imported via the camera connection kit (cck) , then simply swipe the picture, and delete.  If the pictures were downloaded from i tunes during a sync, the only way you can get them off is to re sync.
    In i tunes, open the photo tab.  There are a couple of boxes that control the process.  The first thing to look at is 'sync all' versus 'sync selected'.  Make sure the sync all box is not checked.  Then check the particu
    Ar folders to make sure the ones you want are the ones you want.      
    Look inside the folders, while you are at it.  Sometimes the same picture may exist in multiple folders, so it gets synced even if you did not want it to.

  • Layout bounds vs. painting bounds - how to avoid movement from effects?

    I have a component that I apply a dropshadow effect to when it's hovered over. This causes a visual glitch as the addition of the dropshadow increases the bounds of the component and so I see it shift in the layout as it is moused over.
    What is the best pattern to avoid this?
    Do I need to override getLayoutBounds and do something fancy?
    I want a solution that doesn't require code changes if my stylesheet is changed and the size of the dropshadow changes because of that.

    setPickOnBounds(false) did fix my mouse event issues.
    But I am left with the odd layout behaviour.
    I have a structure like this:
    AnchorPane->BorderPane->Pane-> (bunch of this same structure starting with AnchorPane can be nested within - user can position them by dragging)
    The AnchorPane can be resized by the user - to set the minimum size (using setMinWidth/Height). If the min size is less than preferred size, the layout engine does the right thing and uses the preferred size. I.e. if I drag the nested content to the lower-right past the min size that was set by the user dragging the corner then the whole structure expands to keep the children contained. This works using either Group or Pane as the center component of my BorderPane (the east and west components are filled with VBoxs that have other stuff in them).
    However... when I drag to change the min size of one of the nested AnchorPanes, while it draws that AnchorPane at the correct size, the parent is not resized to take the new size in to account -- UNLESS I move the nested structures of the resized AnchorPane - then I see the parent structure resizing as if it is accommodating only the preferred size of the nested parts, not the actual size of the nested parts as painted and dictated by the min size.
    It's hard to describe, I hope I'm communicating it...
    Basically it seems that Pane uses preferred size and not the actual size of child nodes when computing its preferred size. The min size of child nodes being greater than the preferred size of the child nodes does not affect the layout of the parent Pane.

  • How to avoid mail from erasing old mails

    im getting kind of frustrated w/mail erasing old emails i think they last about 3 - 4 weeks im not sure ... but is there a way to just keep everything and only erase them whenever i want to erase them?... thanx

    Who is the provider of your email account, and is it IMAP or POP? If you are using an AOL IMAP account, for example, their policy is to remove messages from your Inbox folder after 27 days. More info, please, as Mail does not have any setting within it to remove messages from any Inbox.
    Ernie

  • Avoid triggers in IMP or EXP

    Hello,
    How to avoid triggers in IMP or EXP.
    TRIGGERS=Y/N is not available in 11g also.
    Any other tricks?
    with regards
    -mathews p samuel

    No other tricks. With the data pump, you can exclude triggers on the impdp command line.

  • How to avoid printing a page if does not contain data in smart forms

    deat all,
    here is urgent requirement for me .
    i have 3 pagelayouts in smartforms.
    if there is no data in page 2 how to avoid it from printing(the second page should not come in even if it contains hedings and logo)

    try like this
    if@section:IND=1
    this template
    end ifsectionbreak
    if@section:IND=2
    this template
    end if

  • How to avoid the dialogue when converting from context menu

    This is a follow-up to http://forums.adobe.com/message/2016146#443364 which was locked due to a bug.
    i would like to know how i can avoid the 'save as' dialogue when using the context menu to convert a word file to pdf using windows XP/acrobat 8/word 2007.
    so far, it always prompts me for the filename, which is annoying as it does not allow me to batch-convert several files and let the thing run its course.
    the solution provided by Steve in the other thread does not work - even if the plugin from word does not propt for a filename, it still does when triggered from explorer/context menu.
    so back to square one: how to avoid that dialogue when not opening word at all?
    cheers, thanks for any help. michael

    For a permanent change, START>PRINTERS>right click on Adobe PDF printer and select properties>General>Printing Preferences>Adobe PDF Settings. Under the settings tab, uncheck the box related to asking for a name. Pretty sure that is the location, but it may vary with version.

Maybe you are looking for

  • Help NEEDED!! WSVR4400N VPN & QuickVPN setup

    I have the 4400n router. I want to connect to my office using the VPN & QuickVPN setup. Office: Small Biz server 2003 set to a "workgroup" network setup only. WSVR4400N router and Comcast internet Router: I setup the VPN Client Name and password. It

  • Output jframe information to command window

    Hi all I have a program that tracks the assets of a customer, kind of like a cart that holds cds, appliances, etc... I wanted to be able to print out the results to the command window after they enter the number of how many items from what the user e

  • SCUP update failure: Error and 0x800b0004 and 0x80246002

    Hi, I'm trying to get Adobe products using SCCM2012R2 and SCUP 2011.  The site server and distribution point are on the same machine, and the WSUS server sits on a different machine.  We have a root CA which uses AD Certificate Services.  My code sig

  • Encoding with HV20 in PPCS3: Bad quality at 1MB bitrate

    Hello, When I encode my video from my hv20 (1920 x 1080 - 30p) with PPCS3 using H.264 at Bitrate 2MB I get very good results. However when I choose 1MB the video quality is very pixelated and distorted. When I use my Panasonic HMC-150 I can encode at

  • Sharing TREX indexes between portal instances

    Hi people, We created several TREX search indexes in our development portal and we need to reuse them in our productive environment. As I read in Migrating Content, changing namespace I understand that the indexes cannot be transported between portal