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 问题的解决
157 0
|
Oracle 关系型数据库 数据库
【DG】搭建DG时,报错:ORA-01017 invalid username password logon denied
【DG】搭建DG时,报错:ORA-01017 invalid username password logon denied
935 0
|
关系型数据库 MySQL SQL
[解决] Error Code: 1044. Access denied for user 'root'@'%' to database
今天在测试集群用的mysql上,遇到个权限的问题: SQLException : SQL state: 42000 com.mysql.jdbc.exceptions.
5431 0
|
SQL
ORA-00030: User session ID does not exist.
同事在Toad里面执行SQL语句时,突然无线网络中断了,让我检查一下具体情况,如下所示(有些信息,用xxx替换,因为是在处理那些历史归档数据,使用的一个特殊用户,所以可以用下面SQL找到对应的会话信息): SQL> SELECT B.
1928 0
|
Oracle 关系型数据库 Linux
20180226alter system archive log current
[20180226]alter system archive log current.txt --//当日志写满以后,切换日志归档大部分由归档进程ARCH负责将在线重做日志归档.
982 0