动态DDL语句执行和Schema Objects的显示授权问题

这是一个大家常见的问题,也是很容易忽略的问题,尤其是在Procedure里面动态执行DDL语句的时候发生. 我们必须使用显示授权方式来保证DDL的执行权限, 而不能通过role的传递方式,下面是一个简单的测试过程来验证这一点.

参考说明:

If the referenced item is indeed declared and you believe that you have privileges to refer to that item, check the privileges; if the privileges were granted only via a role, then this is expected and documented behavior. Stored objects (packages, procedures, functions, triggers, views) run in the security domain of the object owner with no roles enabled except PUBLIC. Again, you will be notified only that the item was not declared

 

Test steps:

SQL> create user chris identified by pass;

 

User created.

 

SQL> grant dba to chris;

 

Grant succeeded.

 

SQL> connect chris/pass;

Connected.

SQL> create table test1 (name varchar2(10));

Table created.

 

--Success here.

SQL> drop table test1;

 

Table dropped.

 

SQL> create or replace procedure chris_cr_tbl

  2  IS

  3  begin

  4  execute immediate 'create table test1 (name varchar2(10))';

  5  end;

  6  /

 

Procedure created.

 

SQL> exec chris_cr_tbl;

BEGIN chris_cr_tbl; END;

 

*

ERROR at line 1:

ORA-01031: insufficient privileges

ORA-06512: at "CHRIS.CHRIS_CR_TBL", line 4

ORA-06512: at line 1

 

--Failed Here

SQL> connect test/oracle

Connected.

SQL> grant create table to chris;

 

Grant succeeded.

--Explicit Grant

SQL> connect chris/pass

Connected.

SQL> exec chris_cr_tbl;

 

PL/SQL procedure successfully completed.

 

SQL> select table_name from all_tables where owner='CHRIS';

 

TABLE_NAME

------------------------------

TEST1

 

SQL> drop table test1;

 

Table dropped.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值