Create a Sequence, through a Trigger. Oracle

Asked

Viewed 108 times

1

I’m trying to create a sequence in a trigger.

When trying to create by Execute Immediate, I’m getting the following feedback:

ORA: 4092 - Cannot commit in a Trigger.

For all I’ve researched, use the Execute Immediate in a Trigger is not possible as he is in a dll that issues a commit automatic.

I wonder if there is any other way to create a Quence for a Rigger.

Follow the code of Trigger

CREATE OR REPLACE TRIGGER "TR_TEST"  
  AFTER UPDATE ON TEST_TABLE
  FOR EACH ROW
DECLARE
BEGIN
   BEGIN
     EXECUTE IMMEDIATE 'CREATE SEQUENCE SEQ01' ||
                       '      MINVALUE 1' ||
                       '      MAXVALUE 999999999999999999999999999' ||
                       '      START WITH 1' ||
                       '      INCREMENT BY 1' ||
                       '      NOCACHE';      
   EXCEPTION
       WHEN OTHERS THEN
          RAISE_APPLICATION_ERROR(-20200, 'Error');
   END;  
END 
  • Include the code of your attempt

  • I edited and entered the code

2 answers

0


A Trigger should not create an object. Each time it is fired, it will attempt to create the object again... From what I understand, you want to increment the SEQ01 sequence after the TEST_TABLE table update. Right? If so, within the immediate run it should contain:

select SEQ01.nextval from dual;

Since you created Quence earlier.

  • In fact, there is a validation by looking at the name of Quence to see if it already exists, if it does not exist, it will be created.

0

  • So Uerlen, I tried to do this, I played the creation of the sequence in a precedent and called it in Trigger, but it returns the same error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.