Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, santhoshreddy.

Asked: November 01, 2016 - 7:51 am UTC

Last updated: November 02, 2016 - 12:53 am UTC

Version: 11

Viewed 1000+ times

You Asked

Hi,
I excuted below query

SELECT *
FROM dba_objects
WHERE object_name LIKE 'DBA_OBJE%'

then i noticed on thing that dba_objects view and synonym has same name,but oracle doesnot allow us to create any data base object with same name already assigned to another object. but why this have same name?


Thank you.

and Connor said...

Public synonyms are 'special'

SQL> create table t ( x int);

Table created.

SQL> create synonym t for t;
create synonym t for t
*
ERROR at line 1:
ORA-01471: cannot create a synonym with same name as object


SQL> create public synonym t for t;

Synonym created.


This works because "Behind the scenes" the synonym is owned by someone else (a user called PUBLIC). The same works for normal schemas, eg

SQL> create synonym scott.t for t;

Synonym created.



Hope this helps

Is this answer out of date? If it is, please let us know via a Comment