What is the difference between the two? In both the cases? what happens to the privileges granted on this function? Are automatically revoked in both the cases and have to be provided again while re-creating? Kindly explain.
The big difference between create, and create or replace, is that create or replace will always replace an existing object of the same type. You need to be really sure that that is what you want to do. A lot of tools out there will automatically use create or replace when you use the tool to make a new procedure.
The OR REPLACE option on the CREATE TABLE statement can be used to change an existing table definition. Using CREATE OR REPLACE TABLE lets you consolidate the master definition of a table into one statement.
With Oracle CREATE OR REPLACE, the OR REPLACE clause allows the compiler to replace a procedure if a procedure of the same name is already in the database schema. This aspect of the Oracle CREATE OR REPLACE procedure is handy during development as you do not have to drop the procedure each time before recreating it.
[OR REPLACE] option allows the modification of an existing procedure. The optional parameter list contains name, mode and types of the parameters. IN represents the value that will be passed from outside and OUT represents the parameter that will be used to return a value outside of the procedure.
When an object is dropped everything associated with it is dropped too, including privileges. This is not true of CREATE OR REPLACE.
SQL> create procedure p1 is
2 begin
3 null;
4 end;
5 /
Procedure created.
SQL> grant execute on p1 to xyz;
Grant succeeded.
SQL> select * from user_tab_privs_made
2 /
GRANTEE TABLE_NAME GRANTOR PRIVILEGE GRA HIE
------------------------------ ------------------------------ ------------------------------ ---------------------------------------- --- ---
XYZ P1 APC EXECUTE NO NO
SQL> create or replace procedure p1 is
2 n pls_integer;
3 begin
4 n := 1;
5 end;
6 /
Procedure created.
SQL> select * from user_tab_privs_made
2 /
GRANTEE TABLE_NAME GRANTOR PRIVILEGE GRA HIE
------------------------------ ------------------------------ ------------------------------ ---------------------------------------- --- ---
XYZ P1 APC EXECUTE NO NO
SQL> drop procedure p1;
Procedure dropped.
SQL> create or replace procedure p1 (p in out pls_integer) is
2 begin
3 p := p+1;
4 end;
5 /
Procedure created.
SQL> select * from user_tab_privs_made
2 /
no rows selected
SQL>
I believe if you replace a function, the privileges stay intact, although I usually like to create public synonyms and grant privileges to those.
The docs say:
REPLACE is an optional keyword used in object definitions (DDL) to override the older objet definition with a new one. It retains the access privileges of the object during the definition modification process. If the object is dropped and recreated, however, its privileges are lost.
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