Authid Current_User的使用

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

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,要不然只能显示的进行授权,不方便管理不说,且开发的时候可能会很复杂。

 

目录
相关文章
|
8月前
|
Ubuntu 数据安全/隐私保护
All data created during this guest session will be deleted when you log out 问题的解决
All data created during this guest session will be deleted when you log out 问题的解决
|
5月前
|
存储 关系型数据库 MySQL
The user specified as a definer (‘root‘@‘%‘) does not exist
The user specified as a definer (‘root‘@‘%‘) does not exist
EnvironmentNotWritableError: The current user does not have write permissions to the targe...
EnvironmentNotWritableError: The current user does not have write permissions to the targe...
1805 0
|
关系型数据库 MySQL
The user specified as a definer (‘root‘@‘%‘) does not exist(已解决)
The user specified as a definer (‘root‘@‘%‘) does not exist(已解决)
375 0
The user specified as a definer (‘root‘@‘%‘) does not exist(已解决)
|
SQL 关系型数据库 MySQL
MySQL中USER()和CURRENT_USER()的区别
USER()和CURRENT_USER()的一点不同
115 0
|
关系型数据库 MySQL 数据库
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
220 0
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
|
存储
One order里user status和system status的mapping逻辑
One order里user status和system status的mapping逻辑
One order里user status和system status的mapping逻辑
|
SQL
ORA-00030: User session ID does not exist.
同事在Toad里面执行SQL语句时,突然无线网络中断了,让我检查一下具体情况,如下所示(有些信息,用xxx替换,因为是在处理那些历史归档数据,使用的一个特殊用户,所以可以用下面SQL找到对应的会话信息): SQL> SELECT B.
1875 0
|
SQL 测试技术 数据库
0131 ORA-00942 and AUTHID CURRENT_USER
[20180131]ORA-00942 and AUTHID CURRENT_USER.txt --//偶尔写一个存储过程调用一些系统视图.经常遇到一些ORA-00942,有时候很烦.
1124 0