Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly make a public synonym

This is a pretty silly one, but I need help.

I have a table owned by mydbowner. It is named mydbowner.mytable. I tried to make a public synonym by issuing the command:

CREATE OR REPLACE PUBLIC SYNONYM mytable FOR mydbowner.mytable;

When I do this, and I query the table I get:

ORA-01775: looping chain of synonyms

How do I make this synonym without having the problem.

like image 361
Joe Avatar asked Jan 24 '12 22:01

Joe


People also ask

How do you make a public synonym?

Use the CREATE SYNONYM statement to create a synonym, which is an alternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym. Synonyms provide both data independence and location transparency.

What is the correct syntax for creating a private synonym?

Just omit the private keyword. If you omit this clause, then the synonym is private and is accessible only within its schema. A private synonym name must be unique in its schema.

How do you drop a public synonym?

To drop a PUBLIC synonym, you must have the DROP PUBLIC SYNONYM system privilege. You must specify PUBLIC to drop a public synonym. You cannot specify schema if you have specified PUBLIC . Specify the schema containing the synonym.


1 Answers

I think Justin is on the right track. What I think it actually means is that mydbowner.mytable doesn't exist.

Here's an example:

SQL> conn mbobak
Enter password: 
Connected.
SQL> drop table mytable;
drop table mytable
           *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> create public synonym mytable for mbobak.mytable;

Synonym created.

SQL> select * from mytable;
select * from mytable
              *
ERROR at line 1:
ORA-01775: looping chain of synonyms

I think what's happening is that Oracle tries to resolve mytable, there is no mytable in mbobak schema, so it looks for it in PUBLIC, it finds it, and sees that it points to mbobak.mytable. But, mbobak.mytable doesn't exist, so, it looks for mytable in PUBLIC, and there's the loop.

And in fact, if you create mytable, the error goes away:

SQL> create table mytable as select * from dual;

Table created.

SQL> select * from mytable;

D
-
X

1 row selected.

SQL> drop table mytable;

Table dropped.

SQL> select * from mytable;
select * from mytable
              *
ERROR at line 1:
ORA-01775: looping chain of synonyms

Yes, I realize that doesn't really entirely make sense, as, once the public synonym resolved to mbobak.mytable, and that's not found, it seems to me, it should return an error ORA-942 "table or view does not exist", which makes far more sense to me.

But, this does seem to be how it works.

QED

Hope that helps.

like image 185
Mark J. Bobak Avatar answered Nov 08 '22 18:11

Mark J. Bobak