Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping chain of synonyms: how to identify? 1

Status
Not open for further replies.

SJSFoxPro

Technical User
Jun 19, 2003
110
US
Does anyone have a cleverly written query against the data dictionary views (or any other method) to identify a looping chain of synonyms?

Apparently, synonyms have been created that point to the same object and to each other and have, in turn, created a circular reference. (No punn intended ;-) )
 
SJS,

First, here are some sample data:
Code:
SQL> create synonym s1 for s2;

Synonym created.

SQL> create synonym s2 for s3;

Synonym created.

SQL> create synonym s3 for s4;

Synonym created.

SQL> create synonym s4 for s1;

Synonym created.

Notice the "recursive" nature of the synonym chain from "S1 down to S4, then back again to S1". Here then is code to display the relationships amongst the synonyms, including code to "trap and display" the recursion:
Code:
set serveroutput on format wrap
prompt
declare
	connect_by_loop exception;
	pragma exception_init(connect_by_loop,-1436);
	hold_prev_synonym_name	user_synonyms.synonym_name%type;
begin
	dbms_output.put_line('Synonym Hierarchy');
	dbms_output.put_line('----------------------------------------');
	for x in (select lpad(' ',level * 3) || synonym_name a
			,synonym_name b
		    from user_synonyms
		 connect by prior synonym_name = table_name
		   start with synonym_name = 'S3') loop
		hold_prev_synonym_name := x.b;
		dbms_output.put_line(x.a);
	end loop;
	exception
		when connect_by_loop then
			dbms_output.put_line(
				 'Error: connect-by loop following "'
				||hold_prev_synonym_name||'"');
end;
/

Synonym Hierarchy
----------------------------------------
   S3
      S2
         S1
            S4
               S3
                  S2
                     S1
Error: connect-by loop following "S1"

PL/SQL procedure successfully completed.
Let us know if this satisfies your need.
[/code]

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Hi Dave,

I knew you'd come through on this one!

I did find my problem yesterday, however, it was more of a manual search to narrow down the list of tables that were involved and then a close look at each one (a little time consuming). For future use, I want this in my "tool kit" to locate the culprit quicker!

If I don't know any of the synonyms involved in the loop and I want to query all synonyms to see if any cause recursion, do I just randomly select a synonym name to use in the starts with?

Thanks again,
Susan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top