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 design and architecture
Related Q&A from Brian Peasland
Oracle expert Brian Peasland answers one reader's question about common pitfalls when connecting Oracle to outside programs.continue reading
One reader asks expert Brian Peasland a question about datafile sizes with the Oracle RMAN duplicate 10g command.continue reading
Managing parent table-child table relations in Oracle SQL environments is key to efficient programming.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.