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

Dig deeper on Oracle database backup and recovery

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

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.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close