创建视图时ORA-01031

时间:2013-12-09 15:11:11

标签: sql oracle

我开始阅读Tom Kyte的书并立即遇到问题:) - sql执行得很好但基于该sql的CREATE VIEW返回ORA-01031。

以下命令代表“system”用户执行:

create or replace view stats
as select 'STAT...' || a.name name, b.value
      from v$statname a, v$mystat b
     where a.statistic# = b.statistic#
    union all
    select 'LATCH.' || name,  gets
      from v$latch
    union all
    select 'STAT...Elapsed Time', hsecs from v$timer;
  

第3行的错误:ORA-01031:权限不足

但是,执行sql时不会出现错误:

select 'STAT...' || a.name name, b.value
      from v$statname a, v$mystat b
     where a.statistic# = b.statistic#
    union all
    select 'LATCH.' || name,  gets
      from v$latch
    union all
    select 'STAT...Elapsed Time', hsecs from v$timer;

1 个答案:

答案 0 :(得分:3)

system用户缺少select any dictionary权限,或直接授予select on [v_$mystat|v_$statname | v_$latch]对象权限(不是通过dba角色),而不是create view权限。这是您无法在系统架构中创建该视图的主要原因。只要您向system用户授予上述特权之一,您就可以成功创建视图,但是,尝试从不在系统架构中创建用户对象,它是syssystem。创建单独的用户,授予适当的权限并执行您想要执行的任何操作。

SQL> show user;
USER is "SYSTEM"

SQL> create or replace view v_1 as
  2    select *
  3      from v$mystat;

from v$mystat
         *
ERROR at line 3:
ORA-01031: insufficient privileges 


SQL> conn / as sysdba
Connected.

SQL> grant select any dictionary to system;

Grant succeeded.

SQL> conn system/pwd -- connect as system

Connected.

SQL> create or replace view v_1 as
  2    select *
  3      from v$mystat;

View created.

SQL> drop view v_1;

View dropped.