- Community Pick
- Experts Exchange Approved
The data dictionary holds a wealth of information about your objects, but sometimes seemingly easy questions are still difficult to answer with a simple query to one of the views. Somebody once asked me how to determine what object was pointed to by a synonym. That's easy, just query DBA_SYNONYMS. The question becomes more complicated though if the target object is itself a synonym. Then you need to use hierarchical queries (i.e. CONNECT BY or recursive WITH clauses.) Answering this question is made even more difficult by changes in the way synonyms are resolved if the target doesn't exist.
Prior to 10g this condition would produce an error. Starting in 10g you can sometimes use a public synonym of the same name to fill in for the missing object. To this was added a further requirement of displaying the object type of the final object in the synonym chain.
The function below is what I came up with to answer the question. By default it resolves synonyms by 10g rules. You can pass in any number less than 10 to change to the pre-10g method. If a synonym chain resolves to some object in a remote database that's as far as I search and identify the final object as REMOTE. I also keep track of the synonym chain as it's built, so if a synonym loop is created, it will be detected and identified.
Since the output is of VARCHAR2 type, there is an implicit upper limit of 32K on the output in pl/sql or 4K in sql; but I've never encountered a synonym chain that came anywhere close to those limits in a real system.
It was a seemingly easy question that produced an interesting answer that was fun to write.
The Code
Example Usage
Here you can see DBMS_STANDARD is a PUBLIC synonym pointing to an object of the same name owned by SYS. That object is a package.
Here the function is used to identify the cause of ORA-01775 looping error
And finally, here's an example of a tracing a synonym across a dblink. In this case "C" points to a remote table "CLIENTS" but the function doesn't traverse the remote dictionary so the type of the remote object is unknown and labeled so.
by: wasimibm on 2011-12-20 at 11:05:31ID: 33813
you have got tremendous knowledge of oracle..
please continue writing articles.. this will help people like who can make out their oracle concepts clear..
thanks again buddy...!!!