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.
Dig Deeper on Oracle database administration
Related Q&A from Brian Peasland
Readers ask SearchOracle.com expert Brian Peasland where they can find learning materials for becoming a better Oracle database administrator. Continue Reading
In this expert answer, Brian Peasland explains how to call a stored procedure inside user-defined functions in Oracle Database. Continue Reading
One reader asks how he can make a copy of his Oracle Database but not have any data in it, for test purposes. Continue Reading