Q
Manage Learn to apply best practices and optimize your operations.

How to create an index using a procedure in Oracle

How can we create an index using a procedure?

How can we create an index using a procedure?

You'll have to use dynamic SQL and the EXECUTE IMMEDIATE command to create the index in the procedure. Such a stored...

procedure may look like the following:

CREATE PROCEDURE my_pro
AS
  stmt  VARCHAR2(200);
BEGIN
  stmt := 'CREATE INDEX my_index ON my_table(columnZ)';
  EXECUTE IMMEDIATE stmt;
END;
/
From the above, it should be easy to modify the code for your situation.

I would caution you that creating objects on the fly is normally considered a bad practice and is usually the result of a poor database design. So make sure you have a well-designed database schema before implementing this procedure.

This was last published in June 2007

Dig Deeper on Oracle database design and architecture

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.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close