2

I am connected into Oracle 10g database with user "user", when i run a select on DBA_ROLES it displays the result without any problem, but when the select is inside a procedure it returns the error ORA-00942: table or view does not exist

用户是否缺少某些特权?为什么可以执行 SELECT 但不能将其包含在过程中?

SQL> SELECT COUNT(*) FROM DBA_ROLES;

  COUNT(*)
----------
        18

SQL> CREATE OR REPLACE PROCEDURE tst_role IS 
     v VARCHAR2(100);
BEGIN
        v := '';
        FOR rec IN (SELECT ROLE FROM DBA_ROLES) LOOP
                v := rec.role;
                DBMS_OUTPUT.put_line(v);
        END LOOP;
END;
/
Warning: Procedure created with compilation errors.

SQL> show errors
Errors for PROCEDURE TST_ROLE:

LINE/COL ERROR
-------- -----------------------------------------------------------------
5/13     PL/SQL: SQL Statement ignored
5/30     PL/SQL: ORA-00942: table or view does not exist
6/3      PL/SQL: Statement ignored
6/8      PLS-00364: loop index variable 'REC' use is invalid
4

1 回答 1

9

在定义者的权限存储过程中,您无权访问通过角色授予的权限。这很可能意味着您使用的任何 Oracle 用户都已DBA_ROLES通过角色而不是通过直接授权获得访问权限。最有可能的是,您可以要求您的 DBA 授予您的帐户SELECT ANY DICTIONARY权限

GRANT SELECT ANY DICTIONARY
   TO your_oracle_user

您可以通过禁用会话中的角色并验证您是否收到错误来验证问题是否确实是通过角色授予的。如果你

SQL> set role none;
SQL> SELECT COUNT(*) FROM DBA_ROLES;

我敢打赌你会得到同样的 ORA-00942 错误。

于 2013-02-28T16:15:33.030 回答