查询正在运行,但查看未创建

时间:2014-05-26 17:39:49

标签: oracle view grant

我是Oracle新手。我能够执行:

SELECT X, Y, Z. 
FROM SCH2.TAB_A A JOIN SCH2.TAB_B B ON A.CODE = B.CODE
LEFT OUTER JOIN SCH2.MY_V MV ON MV.CODE = B.CODE
WHERE  MV.STATUS = 'A';

但是当我试图将这个SELECT语句放在视图中时,我收到错误:

ORA-00942:表或视图不存在

CREATE OR REPLACE VIEW SCH1.NEW_V AS
SELECT X, Y, Z. 
FROM SCH2.TAB_A A JOIN SCH2.TAB_B B ON A.CODE = B.CODE
LEFT OUTER JOIN SCH2.MY_V MV ON MV.CODE = B.CODE
WHERE  MV.STATUS = 'A';
/

尝试谷歌,

SQL Error: ORA-00942 table or view does not exist

http://www.techonthenet.com/oracle/errors/ora00942.php

但仍然无法解决。如果我能够运行查询,为什么我在尝试将其放入View中时会出现错误。

2 个答案:

答案 0 :(得分:2)

检查您是否具有直接访问权限,而不是通过角色:

SQL> create user sch1 identified by sch1;

SQL> create role scott_acc;

SQL> grant select on scott.emp to scott_acc;

SQL> grant scott_acc to sch1;

SQL> create or replace view sch1.v_1
  2  as select * from scott.emp;
as select * from scott.emp
                       *
error in line 2:
ORA-00942: table or view does npt exist


SQL> grant select on scott.emp to sch1;


SQL> create or replace view sch1.v_1
  2  as select * from scott.emp;

View created.

答案 1 :(得分:0)

这有帮助

Oracle Create View issue

GRANT SELECT ON SCH2.TAB_A TO SCH1;

GRANT SELECT ON SCH2.TAB_B TO SCH1

GRANT SELECT ON SCH2.MY_V TO SCH1;