1)Auth ID about DDL language in Dynamic SQL
1@@@@with AUTHID CURRENT_USER option
HR@ocm> !cat tmp.sql
CREATE OR REPLACE PROCEDURE exec_DDL
( ddl_string IN VARCHAR2 )
AUTHID CURRENT_USER
IS
BEGIN
EXECUTE IMMEDIATE ddl_string; --Who is the table belong to
--sh create a table using this procedure,
--check who is that table belong to !!!
END;
/
HR@ocm> @tmp.sql
Procedure created.
HR@ocm> GRANT execute ON exec_DDL TO sh;
Grant succeeded.
@@@login by sh, check
SH@ocm> EXEC hr.exec_DDL('CREATE TABLE who_am_I_belong_to(a int)');
PL/SQL procedure successfully completed.
SH@ocm> set lines 60
SH@ocm> desc who_am_I_belong_to
Name Null? Type
----------------------------- -------- --------------------
A NUMBER(38)
HR@ocm> desc who_am_I_belong_to
ERROR:
ORA-04043: object who_am_I_belong_to does not exist
@@@Summary:
obviously, who is calling the procedure, the object is belong to who use the DDL to create it
When you use AUTHID CURRENT_USER before IS keyword.
this option is that running the code in this plsql object by the current user.
No matter who the plsql is belong to.
2@@@@without AUTHID CURRENT_USER option
HR@ocm> !cat tmp.sql
CREATE OR REPLACE PROCEDURE exec_DDL
( ddl_string IN VARCHAR2 )
IS
BEGIN
EXECUTE IMMEDIATE ddl_string; --Who is the table belong to
--sh create a table using this procedure,
--check who is that table belong to !!!
END;
/
HR@ocm> @tmp.sql
Procedure created.
HR@ocm> GRANT execute ON exec_DDL TO sh;
Grant succeeded.
@@@login by sh, check
SH@ocm> EXEC hr.exec_DDL('CREATE TABLE who_am_I_belong_to(a int)');
BEGIN hr.exec_DDL('CREATE TABLE who_am_I_belong_to(a int)'); END;
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "HR.EXEC_DDL", line 5
ORA-06512: at line 1
@@@Summary
without AUTHID CURRENT_USER option, you could not use it.
Note: default option is AUTHID DEFINER, here it is