How to execute DML in an Oracle trigger with EXECUTE IMMEDIATE

Is it possible to create an index within a trigger? I have to do that because to optimize my process I need an additional index on a table (that is created on the fly by another product). If the index doesn't exist, I create it. Last time I tried it I got a message that the DML is not authorized in the trigger.

    Requires Free Membership to View

You can execute DML in a trigger if that DML is part of the EXECUTE IMMEDIATE statement similar to the following:

CREATE TRIGGER my_trig 
….
BEGIN
   Stmt := 'CREATE INDEX my_index ON my_table(column)';
   EXECUTE IMMEDIATE Stmt;
END;
/

This was first published in November 2009

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.