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.
ALTER PROCEDURE does not change permissions and does not affect any dependent stored procedures or triggers.
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.
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.
No, you cannot rename a procedure. You need to create a new one. Oracle does not support renaming PL SQL procedures.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With