0131 ORA-00942 and AUTHID CURRENT_USER

简介: [20180131]ORA-00942 and AUTHID CURRENT_USER.txt --//偶尔写一个存储过程调用一些系统视图.经常遇到一些ORA-00942,有时候很烦.

[20180131]ORA-00942 and AUTHID CURRENT_USER.txt

--//偶尔写一个存储过程调用一些系统视图.经常遇到一些ORA-00942,有时候很烦.有时候加AUTHID CURRENT_USER可以过去,有一些不行.

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING          VERSION    BANNER
-------------------- ---------- ----------------------------------------------------------------------------
x86_64/Linux 2.4.xx  11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

--//scott 用户是dba,权限如下:
CREATE USER SCOTT
  IDENTIFIED BY
  DEFAULT TABLESPACE USERS
  TEMPORARY TABLESPACE TEMP
  PROFILE DEFAULT
  ACCOUNT UNLOCK;
  -- 3 Roles for SCOTT
  GRANT CONNECT TO SCOTT;
  GRANT DBA TO SCOTT;
  GRANT RESOURCE TO SCOTT;
  ALTER USER SCOTT DEFAULT ROLE ALL;
  -- 5 System Privileges for SCOTT
  GRANT CREATE DATABASE LINK TO SCOTT;
  GRANT EXPORT FULL DATABASE TO SCOTT;
  GRANT IMPORT FULL DATABASE TO SCOTT;
  //GRANT SELECT ANY DICTIONARY TO SCOTT;
  GRANT UNLIMITED TABLESPACE TO SCOTT;
  -- 2 Object Privileges for SCOTT
    GRANT EXECUTE ON SYS.DBMS_SESSION TO SCOTT;
    GRANT EXECUTE, READ, WRITE ON DIRECTORY TOAD_BDUMP_DIR TO SCOTT WITH GRANT OPTION;

2.测试1:
SCOTT@book> select count(*)  from v$session ;
  COUNT(*)
----------
        29
--//在scott用户下访问是ok的.

CREATE OR REPLACE PROCEDURE TEST2
AUTHID  CURRENT_USER
IS
  v_n number;
begin
  select count(*) into v_n from v$session ;
  dbms_output.put_line(v_n);
end;
/

SCOTT@book> show error
Errors for PROCEDURE TEST2:
LINE/COL ERROR
-------- -----------------------------------------------
6/3      PL/SQL: SQL Statement ignored
6/33     PL/SQL: ORA-00942: table or view does not exist

--//以前一些blog经常建议
SYS@book> grant select on v_$session to scott;
Grant succeeded.

SCOTT@book> set serverout on
SCOTT@book> exec test2
32
PL/SQL procedure successfully completed.

--//但是如果很多明显不是很方面.

3.测试3:
CREATE OR REPLACE PROCEDURE TEST3
AUTHID  CURRENT_USER
IS
  v_n number;
begin
  select count(*) into v_n from &1;
  dbms_output.put_line(v_n);
end;
/

--//比如如上我带入dba_objects就出问题,而使用all_objects就没有问题.两者的差别到底在那里.

--//而且all_objects的定义更加复杂!!


SYS@book> grant select any dictionary to scott;
Grant succeeded.
--//有了这个权限,过程test2也可以执行.

SYS@book> revoke select on v_$session from scott;
Revoke succeeded.

SCOTT@book> set serverout on
SCOTT@book> exec test2
31
PL/SQL procedure successfully completed.

目录
相关文章
|
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 问题的解决
132 0
delete in ST05 trace - deletion will also lead to many DB access first
delete in ST05 trace - deletion will also lead to many DB access first
116 0
delete in ST05 trace - deletion will also lead to many DB access first
|
SQL
ORA-00030: User session ID does not exist.
同事在Toad里面执行SQL语句时,突然无线网络中断了,让我检查一下具体情况,如下所示(有些信息,用xxx替换,因为是在处理那些历史归档数据,使用的一个特殊用户,所以可以用下面SQL找到对应的会话信息): SQL> SELECT B.
1907 0
|
存储 SQL 数据库管理
Authid Current_User的使用
Authid Current_User  的使用 在开发过程中,会遇到用户拥有的role权限在存储过程中是不可用的,遇到这种情况,经常采用一般需要显示授权,如:grant create table to user  grant truncate table to user ;这种方式是可以解决问题,当时很繁琐,有可能会执行N多grant才能执行存储过程,然后oracle很智能的提供了在存储过程中使用用户role权限的方法,在存储过程中添加 Authid Current_User,这样做相当于给调用者授权。
1258 0