创建触发器报PL/SQL: ORA-00942: 表或视图不存在

来源:互联网 发布:geo数据库简介 编辑:程序博客网 时间:2024/06/13 02:22

创建触发器报PL/SQL: ORA-00942: 表或视图不存在,现在如下验证进行重现:

1.创建用户u1赋予dba权限

SQL> create user u1 identified by u1;

用户已创建。

SQL> grant dba to u1;

授权成功。

2.创建用户u2并赋予dba权限
SQL> create user u2 identified by u2;
用户已创建。
SQL> grant dba to u2;

授权成功。

3.在用户u1下创建表tab1
SQL> conn u1/u1
已连接。
SQL> connect u1/u1
已连接。
SQL> create table tab1
  2  (
  3     col1 number,
  4     col2 number
  5  );
表已创建。
SQL>
4.登录到用户u2
C:\Users\Administrator>sqlplus u2/u2
SQL*Plus: Release 11.2.0.1.0 Production on 星期二 11月 4 09:15:38 2014
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
在u2下访问u1的tab1可以访问的(因为u2具有dba权限)
SQL> select * from u1.tab1;
未选定行
5.在u2下创建触发器
SQL> create or replace trigger trg1
  2  before insert or update on u1.tab1
  3  for each row
  4  begin
  5    :new.col2 := :new.col1*2;
  6  insert into u1.tab1 values (1,1);
  7  commit;
  8  end;
  9  /
警告: 创建的触发器带有编译错误。
SQL> show error
TRIGGER TRG1 出现错误:
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/1      PL/SQL: SQL Statement ignored
3/16     PL/SQL: ORA-00942: 表或视图不存在
SQL>

报错报表不存在,疑问表是存在并且是可以访问的


最终定位原因是在触发器中要显式的赋予对表的访问权限
现在把表tab1的select,update ,insert显式赋予用户u2

SQL> show user
USER 为 "U1"
SQL> grant select,update,insert on u1.tab1 to u2;
授权成功。
SQL>
重新编译触发,没有错误编译通过
SQL> show user
USER 为 "U2"
SQL> alter trigger trg1 compile;
触发器已更改
SQL> show error
没有错误。
SQL>
0 0
原创粉丝点击