0

I just created a column synonym

CREATE PUBLIC SYNONYM col_syn FOR X_CHILD.FIRST_NAME;

This was executed without error.

But when i say

select dob, col_syn from x_child;

I get this:

ORA-00904: "COL_SYN": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error at Line: 4 Column: 13

The column "first_name" for sure exists: select * FROM x_child; shows: enter image description here

I've pressed commit at least 18 times and restarted SQL developer. This did not help.

Also, when I click on synonyms in this schema, there's nothing there. And the only synonym i can see is the table synonym. Am I supposed to be able to see the column synonym here too?

enter image description here

3
  • 2
    Documentation says that you can create synonyms for a table, view, sequence, operator, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym. Column is not mentioned, Commented Jul 7, 2020 at 16:31
  • 1
    @PonderStibbons - you beat me to it! But I was able to reproduce a 'successful' CREATE SYNONYM on a column, just like the OP. So I guess the real question is why does oracle not return an error on that?
    – EdStevens
    Commented Jul 7, 2020 at 16:35
  • 1
    Oracle doesn't validate the referenced object. Perhaps they wanted to allow you to create synonyms in advance for things you will define later. It also doesn't remove the synonym if you drop the object, so arguably it's just being consistent. create synonym nonsense for hatstand.banana; runs fine. Commented Jul 7, 2020 at 21:07

1 Answer 1

6

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. You cannot have a synonym to a column

Synonyms provide both data independence and location transparency. Synonyms permit applications to function without modification regardless of which user owns the table or view and regardless of which database holds the table or view. However, synonyms are not a substitute for privileges on database objects. Appropriate privileges must be granted to a user before the user can use the synonym.

When you create the synonym in your example, the reference object does not need to exist at all. In your case

CREATE PUBLIC SYNONYM col_syn FOR X_CHILD.FIRST_NAME; 

you are creating a public synonym ( available for everybody ) which makes a reference to the object X_CHILD ( that is why you have in your dba_synonyms as reference_name X_CHILD ) and as reference_type TABLE ( not column )

Specify the schema to contain the synonym. If you omit schema, then Oracle Database creates the synonym in your own schema. You cannot specify a schema for the synonym if you have specified PUBLIC.

https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/CREATE-SYNONYM.html#GUID-A806C82F-1171-478E-A910-F9C6C42739B2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.