Trigger after the commit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shanahas
    New Member
    • Feb 2010
    • 3

    Trigger after the commit

    I would like to know, how to get a trigger executed only after the commit is performed.
    I have a table A which has a trigger tigg_A. In this trigger it would insert a record in Table B.
    Now i want run a trigger Trigg_B on table B only after the commit is performed for the transaction which caused the insertion of record on Table B(ie the transaction which performed the Trigg_A)
  • OraMaster
    New Member
    • Aug 2009
    • 135

    #2
    If you want to implement such kind of functionality then don't use the triggers. You can do this by using procedure/function since the trigger gets called before/after DML regardless of commit/rollback of DML.

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Try to use PRAGMA AUTONOMOUS TRANSACTION in the trigger at your own risk.

      Comment

      • shanahas
        New Member
        • Feb 2010
        • 3

        #4
        I guess the Pragma Autonomous and Function/procedure will not work in my scenario.Let me explain the scenario in detail.

        I have 3 tables here 1. "Transactio n" 2."Shipment" 3."Staging Table" and a Package "Interface"

        Whenever I do a shipment "Transactio n" Table will execute the trigger on it "Tran_Trigg er" . In this trigger,It will insert the current Transaction details in "Staging Table".Once the records get committed, I need to call the package "Interface" which would pick up the data from "staging table" and update all transaction related tables(detail table) accordingly.
        If I call the this package inside the "Tran_trigg er", it will not be able to update all the trasaction detail tables as the data is not yet committed and as a result the data in detail table is out of sync.I would be able to call the "Interface" package only after the transaction is commited and all details tables are updated.
        So whenever a commit is established i can immediately call the "interface" package otherwise it will cause a delay(if i schedule the package)

        Comment

        • OraMaster
          New Member
          • Aug 2009
          • 135

          #5
          Why do you think PRAGMA AUTONOMOUS_TRAN SACTION will not work in your case. When "Tran_Trigg er" gets called it will COMMIT your "STAGING TABLE". After that you can COMMIT your remaining transaction details and can call the package. If this also will not work in your case then post the code you have done so far.

          Comment

          • shanahas
            New Member
            • Feb 2010
            • 3

            #6
            What you said is true.But let explain why this wont work in my case.
            The Shipment is happening in SIM(a system which i do not have access) during the shipment it triggers the "Transactio n" table in RMS(where my program written) and the staging table is getting poulated.
            Once the "transactio n" table is updated, it will do some updation in SIM and finally get committed.Only after this point of time i can call my package (parameters are picked up from staging table data) as the entire transaction/shipment related tables are up to date.
            Since i'm not sure when the transaction exactly getting completed or getting commited(as it is happening in SIM) i wont be able to call my package immediately after the process(shipmen t) completed. I could call the package on an intervel by using DBMS_JOBS but this will couse a delay as the job runs on a intervel and not immediately after the shipment transaction is completed.
            My idea is, as soon as the transaction is completed(commi ted), i want to call the package so that there is no delay

            Comment

            Working...