Skip to Main Content
  • Questions
  • How to give preference to Private synonyms than Public synonyms

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Bharath.

Asked: October 03, 2015 - 11:44 pm UTC

Last updated: October 04, 2015 - 2:24 am UTC

Version: 11.4.0.2.0

Viewed 1000+ times

You Asked

Tom,

I'm stuck with a situation here.
I have both public & private synonym in a scenario.

Public synonym for a schema's table in same Database
Private synonym for a schema's table in another database using a DB Link

Public Synonym : A - Database 1 - Schema - SChema1.TABLE
Private SYnonym : A - Database 2 - Schema - Schema2.TABLE

I want to use private synonym in above case rather than public synonym.

Select * from table (should use Private synonym to use Database 2 )

I should do this without specifying the schema name like schema2.table

Any ideas?




and Connor said...

I'm not sure what you mean. Private synonyms will always take precedence of public synonyms. For example

DB11
====
SQL> create table T1 ( x int );

Table created.


DB12
====

SQL> create database link db11 using 'db11';

Database link created.

SQL> create table T2 ( y int );

Table created.

SQL> create public synonym XX for T2;

Synonym created.

SQL> create  synonym XX for T1@db11;

SQL> desc XX
 Name                          Null?    Type
 ----------------------------- -------- --------------------
 X                                      NUMBER(38)

SQL>


So you can see that "XX" was resolved to the private synonym not the public one

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