Monday 2 May 2011

ORA-00980: synonym translation is no longer valid

"ORA-00980: synonym translation is no longer valid" is a common error encountered in a development environment. This can happen for many reasons.

Some of them are:

1. You created a synonym on non-existing object by mistake.
* For example, you created a synonym on SCOTT.DEPT where either the SCOTT schema in not present or the DEPT table is missing.
2. You dropped an object but you did not drop the synonyms referencing the object.
3. You dropped a user, but you did not drop synonyms referencing the objects owned by that user.

When an object is dropped, synonyms referring to the object are not dropped. The following script lists all such invalid synonyms:

select * from dba_synonyms s
where table_owner not in('SYSTEM','SYS')
and db_link is null
and not exists
(select 1
from dba_objects o
where s.table_owner=o.owner
and s.table_name=o.object_name);


The following script generates DDL to drop synonyms whose translation is no longer valid. USE WITH CAUTION.

Spool drop.sql

select 'drop '||decode (s.owner,'PUBLIC','PUBLIC SYNONYM ',
'SYNONYM'||s.owner||'.')||s.synonym_name||';'
from dba_synonyms s
where table_owner not in('SYSTEM','SYS')
and db_link is null
and not exists
(select 1
from dba_objects o
where s.table_owner=o.owner
and s.table_name=o.object_name);

execute drop.sql


cheer!!!!!!!!!

3 comments:

  1. this is a simple thing but very effective.....if any confusion pls send a mail to me

    ReplyDelete
  2. nice piece of information, I had come to know about your internet site from my friend vinay, delhi,i have read atleast 12 posts of yours by now, and let me tell you, your website gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new post, once again hats off to you! Thanx a ton once again, Regards, Synonyms In Oracle

    ReplyDelete
  3. i run the above query, i didn't find my synonym names in the results.
    still i am getting "ORA-00980: synonym translation is no longer valid " for synonyms created on views , Synonym created on tables are working fine but some how synonym on view is not working though target item is present , any idea?

    ReplyDelete