Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Stored Procedure with Alter command

I am trying to build an Oracle stored procedure which will accept a table name as a parameter. The procedure will then rebuild all indexes on the table.

My problem is I get an error while using the ALTER command from a stored procedure, as if PLSQL does not allow that command.

like image 589
Will Avatar asked Mar 23 '10 17:03

Will


People also ask

Can we use alter command in stored procedure?

ALTER PROCEDURE does not change permissions and does not affect any dependent stored procedures or triggers.

How do you modify a procedure in Oracle?

The procedure must be in your own schema or you must have ALTER ANY PROCEDURE system privilege. Specify the schema containing the procedure. If you omit schema , then Oracle Database assumes the procedure is in your own schema. Specify the name of the procedure to be recompiled.

Can you ALTER PROCEDURE with in package in Oracle?

Because all objects in a package are stored as a unit, the ALTER PACKAGE statement recompiles all package objects. You cannot use the ALTER PROCEDURE statement or ALTER FUNCTION statement to recompile individually a procedure or function that is part of a package.

How do I rename a stored procedure in Oracle?

No, you cannot rename a procedure. You need to create a new one. Oracle does not support renaming PL SQL procedures.


1 Answers

Use the execute immediate statement to execute DDL inside PL/SQL.

create procedure RebuildIndex(index_name varchar2) as
begin
   execute immediate 'alter index ' || index_name || ' rebuild';
end;

I tested this code; it works.

like image 76
Igby Largeman Avatar answered Sep 22 '22 14:09

Igby Largeman