How to rename an Oracle stored procedure

lwitpub發表於2011-08-30

Is there a way to rename an oracle stored procedure, without having to drop and recreate the procedure?

You can effectively rename a stored procedure by simply creating another procedure - with the new name - that simply calls the old procedure. Here is an example.

create or replace procedure new_procedure_name(variables in type)
as
begin
old_procedure_name(variables in type);
end;
/

[oracle@rh4racdb01 gary]$ cat demo.sql
create or replace procedure test_sql(aa in char)
as
begin
delete from emp where empno=10000;
commit;
end;
/
[oracle@rh4racdb01 gary]$ cat demo_rename.sql
create or replace procedure test_sql_old(bb in varchar2)
as
begin
test_sql(bb);
end;
/
scott@RACDB>@demo.sql

Procedure created.

scott@RACDB>@demo_rename.sql

Procedure created.

scott@RACDB>select object_name,OBJECT_TYPE from user_procedures;

OBJECT_NAME                             OBJECT_TYPE
------------------------------------------------------------ -------------------
TEST_SQL                                      PROCEDURE
TEST_SQL_OLD                             PROCEDURE

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/628922/viewspace-706279/,如需轉載,請註明出處,否則將追究法律責任。

相關文章