Authid Current_User的使用

论坛 期权论坛 脚本     
匿名技术用户   2021-1-4 07:13   25   0

Authid Current_User 的使用

在开发过程中,会遇到用户拥有的role权限在存储过程中是不可用的,遇到这种情况,经常采用一般需要显示授权,如:grant create table to user grant truncate table to user ;这种方式是可以解决问题,当时很繁琐,有可能会执行N多grant才能执行存储过程,然后oracle很智能的提供了在存储过程中使用用户role权限的方法,在存储过程中添加

Authid Current_User,这样做相当于给调用者授权。以下为相关的example


SYS@ orcl >select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

SYS@ orcl >conn test/test
Connected.
TEST@ orcl >create or replace procedure p_test
2 as
3 begin
4 execute immediate'create table t(a number)';
5 end;
6 /

Procedure created.
TEST@ orcl >exec p_test;
BEGIN p_test; END;

*
ERROR at line 1:
ORA-01031: 权限不足
ORA-06512: 在 "TEST.P_TEST", line 4
ORA-06512: 在 line 1

--下面一步查看该用户的role,可以看到拥有dba权限,但是却不能被存储中的execute使用,所以报错
TEST@ orcl >select * from dba_role_privs where grantee='TEST';

GRANTEE GRANTED_ROLE ADM DEF
------------------------------ ------------------------------ --- ---
TEST DBA NO YES

--修改存储过程,添加Authid Current_User
TEST@ orcl >create or replace procedure p_test
2 Authid Current_User
3 as
4 begin
5 execute immediate'create table t(a number)';
6 end;
7 /

Procedure created.

TEST@ orcl >exec p_test;

PL/SQL procedure successfully completed.
--可以看到t表已经创建成功
TEST@ orcl >select * from t;

no rows selected

总结:在存储过程中存在这样的问题,都应该使用Authid Current_User,要不然只能显示的进行授权,不方便管理不说,且开发的时候可能会很复杂。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15489979/viewspace-742760/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15489979/viewspace-742760/

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP