Q

How to execute DML in an Oracle trigger with EXECUTE IMMEDIATE

Read how to execute DML in an Oracle trigger with the EXECUTE IMMEDIATE statement in this tip from Oracle expert Brian Peasland

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.
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 last published in November 2009

Dig Deeper on Oracle database backup and recovery

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close