954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Oracle Autonomous Trigger

Hi

I there a way to make a trigger completely independent from the calling table so that even if the trigger is made invalid, inserts can still be done to the table that calls the trigger?

I created the following trigger:

CREATE OR REPLACE TRIGGER LOCAL.SYNC_TRIGGER
AFTER INSERT ON LOCAL.LOCAL_TABLE FOR EACH ROW
DECLARE
  PRAGMA AUTONOMOUS_TRANSACTION;
  ecode        NUMBER;
  emesg        VARCHAR2(200);
BEGIN
  -- Code to setup data inserted into remote table omitted ...
  --
  --

  INSERT INTO REMOTE_TABLE@REMOTE_DB 
  (
     SEQ,
     COL1,
     COL2,
     ...
  )
  VALUES
  (
     REMOTE_TABLE_SEQ.NEXTVAL@REMOTE_DB, 
     :new.col1,
     :new.col2,
     ...   );
   COMMIT;
   
   EXCEPTION
    WHEN OTHERS THEN
        ecode := SQLCODE;
        emesg := SQLERRM;
        INSERT INTO LOCAL.TRIGGER_EXCEPTIONS (ERROR_DES) VALUES (to_char(ecode)||'-'||emesg);
        COMMIT;
END;
/


The trigger works fine but there were problems recently with users not being able to capture in the local table. It seems some maintenence was done on the remote database and the trigger appeared invalid in Toad. I recompiled the trigger which solved the problem. The following error was found in the TRIGGER_EXCEPTIONS table:ORA-02068: following severe error from REMOTE_DB ORA-01033: ORACLE initialization or shutdown in progress

What can I do to make our local operation unaffected by what happens remotely on the remote DB?

Greg8202
Newbie Poster
11 posts since Oct 2009
Reputation Points: 10
Solved Threads: 1
 

The problem is not with the trigger but the remote database. Since you are working over a DB link , the remote DB should always be available from the calling / referring DB.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

I know that the problem is the remote DB but I have no control over that. Is there anything I can do my side to make the syncing more robust to handle the remote DB becoming unavailable.

Greg8202
Newbie Poster
11 posts since Oct 2009
Reputation Points: 10
Solved Threads: 1
 

So the problem is since you are referring to the remote DB in the INSERT statement inside the trigger, the trigger becomes invalid once the remote DB is not available / goes off line.

What about trying to use EXECUTE IMMEDIATE for the insert statement inside the trigger !

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: