TRUNCATE SYNONYM & ORA-00942

同事可以查询到表中的数据,但truncate这张表的时候抱ORA-00942: 表或视图不存在

开始以为是表名写的有问题,但后来发现他删除的不是,而是一个同义词(synonym

对同义词synonym是不能用truncat的。

 

 

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as scott

 

SQL> SELECT COUNT(1) FROM T_EMP;

  COUNT(1)
----------
         3

 

SQL> TRUNCATE TABLE T_EMP;S

TRUNCATE TABLE T_EMP

ORA-00942: 表或视图不存在

 

SQL> SELECT S.OBJECT_NAME,S.OBJECT_TYPE,s.status FROM user_objects s WHERE s.object_name='T_EMP';

OBJECT_NAME          OBJECT_TYPE           STATUS
--------------------       -------------------         -------
T_EMP                     SYNONYM                 VALID

 

SQL>  SELECT dbms_metadata.get_ddl('SYNONYM','T_EMP')  TEXT FROM dual;

TEXT
--------------------------------------------------------------------------------

  CREATE OR REPLACE SYNONYM "SCOTT"."T_EMP" FOR "SCOTT"."TEST2"

 

SQL> TRUNCATE TABLE TEST2;

Table truncated

 

SQL> SELECT COUNT(1) FROM T_EMP;

  COUNT(1)
----------
         0

SQL>

你可能感兴趣的:(oracle,sql,object,user,table,database)