为便于理解ORA-00980报错的原因,我们通过几种方式来再现这个报错。
1.全新创建sec1和sec2用户用于演示create user sec1 identified by sec1 default tablespace tbs_sec_d;
grant dba to sec1;
create user sec2 identified by sec2 default tablespace tbs_sec_d;
grant dba to sec2;
2.在目标不存在的情况下同名创建是可以成功的
sec@ora10g> conn sec1/sec1
Connected.
sec1@ora10g> create synonym syn_t for sec2.t;
Synonym created.
注意,此时全新用户sec2中是不存在T这张表的,但是sec1用户下可以完成同名的创建。但是此时该同名是不可以使用的。
3.此时查询同名便会抛出ORA-00980错误
sec1@ora10g> select * from syn_t;
select * from syn_t
*
ERROR at line 1:
ORA-00980: synonym translation is no longer valid
4.验证错误是否得到解决
sec1@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> create table t (x varchar2(10));
Table created.
OK,在目标对象存在的情况下,问题得到解决。
5.当目标表名发生变化时问题重现
sec1@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> alter table t rename to t1;
Table altered.
sec2@ora10g> conn sec1/sec1
Connected.
sec1@ora10g> select * from syn_t;
select * from syn_t
*
ERROR at line 1:
ORA-00980: synonym translation is no longer valid
这也是显然的。总之,当同名指向的目标对象不存在的时,查询同名是便会抛出ORA-00980错误。
6.有关ORA-00980报错信息的原因和处理方法参考如下
Error: ORA 980
Text: synonym translation is no longer valid
-------------------------------------------------------------------------------
Cause: The synonym used is based on a table, view, or synonym that no longer
exists.
Action: Replace the synonym with the name of the object it references or re-
create the synonym so that it refers to a valid table, view, or synonym.
7.小结
使用同名时导致ORA-00980报错原因基本上是由于同名指向的目标对象不存在的时发生的。在知道问题原因后,问题处理将会是比较顺畅的。
--转自