Public synonym_OracleSQL - sql

I have created a public synonym in my code, however, I am unable to see it in the all_synonyms or user_synonyms views just to make sure the synonym has created and existed in my database. Help me guys?! Thanks in advance...
I have tried to look in the user_synonyms and all_synonyms or dba_synonyms vies, still unable to find it.
create public synonym EBS_PS as select * from EBS;
(Synonym created)
I should see the public synonym EBS_PS should be stored in a system view.

Your statement is not a valid Oracle statement:
SQL> create public synonym EBS_PS as select * from EBS;
create public synonym EBS_PS as select * from EBS
*
ERROR at line 1:
ORA-00905: missing keyword
To create the synonym you want you do:
create public synonym EBS_PS for EBS;
This will show up in the all_synonyms view.

On the future, I can advice that you should use "or replace" keyword. You can save time for solving the next errors.
create or replace public synonym EBS_PS for EBS;

Related

SQL Developer: Why can't I select by column synonym?

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:
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?
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

How to grant "select" permission on public synonym "SHC.ABC" of table "SHC.ABC"

I created table called "SCH.ABC" and created PUBLIC synonym "SCH.ABC" now I want to Grant "select" permission to schema "SCH1" on synonym "ABC" . How can i do that please help resolving this.
I am creating synanym as same name of table, while granting permission we will not specify object type whether it is a table or a synonym.
If given, grant select on ABC to sch1; then which object type will get granted synonym or table ?
You already created a public synonym called abc, and you can grant selecting to a particular schema as
grant select on abc to sch1;
where you do not need to qualify with schema name as sch.abc by connecting to sys or system schemas.
or you can grant to all schemas as
grant select on abc to public;
and you don't need to qualify the public synonym abc with the schema name. Use
select * from abc;
in every schema in the database.
Thank you very much for your interest to answering it. I just now found that, in that case synonym only will get precedence of grant. I tested by drop synonym in my home Schema and tried accessing it in another schema it was giving error and i again created synonym after that it was working fine.

Sequence neither SELECT nor CREATE in Oracle

I am facing a problem while using sequence in Oracle 11g Express Edition. It's neither accessible nor created.
I tried this query to get NEXTVAL of sequence.
select SEQ_PATIENT.nextval from dual;
It displays error
ORA-02289: sequence does not exist
Then I tried to CREATE the SYNONYM for above sequence as below
create synonym SEQ_PATIENT
for scott.SEQ_PATIENT;
and it returns
ORA-00955: name is already used by an existing object
Why is it so?
This:
select SEQ_PATIENT.nextval from dual;
means that you want to select next value from a sequence whose name is SEQ_PATIENT and it belongs to current schema (i.e. the user you're connected to). Oracle says that you don't have that sequence.
This:
create synonym SEQ_PATIENT for scott.SEQ_PATIENT;
tries to create a synonym (NOT a sequence!) named SEQ_PATIENT for object whose name is SEQ_PATIENT which belongs to user Scott. Oracle says that object with name SEQ_PATIENT already exists.
So: how are you connected to the database? Which user is it?
What is the result of
select * from all_objects where object_name = 'SEQ_PATIENT';
It should tell you who owns it and what it is. Depending on its result, we'll be able to suggest further steps.
I just used DROP SYNONYM and again used CREATE it worked fine.

object name already exists: PUBLIC in HSQLDB

I have an HSQLDB database (script/log) that I want to read into an In-Memory database. This script has near its top:
CREATE SCHEMA PUBLIC AUTHORIZATION DBA;
which leads to an error. So I tried executing that manually and I don't understand the result. Here's what I did:
Why do I get object name already exists: PUBLIC / Error Code: -5504 / State: 42504?
Did I not drop the schema correctly or why am I unable to create it?
The PUBLIC schema exists in all new databases. When you drop the PUBLIC schema, an empty version gets recreated automatically. Therefore, you do not need to create the PUBLIC schema.

can we create synonym with the same name in same schema

I'm preparing for SQL Expert certification, and I found one question and It said,which is the correct option. And, out of four, one option said A table and a synonym can have the same name in the same schema.
And, per my knowledge, in oracle anything we create that treated as an object, which means when we say create synonym, which means we are creating new object. And create same object in same schema not allowed in Oracle or any database AFAIK.
Even Burleson says
You can have a public and private synonym of the same name. In fact,
you can have a public and private synonym called EMP in the SCOTT
schema and have a table called EMP in the same schema
So, I tried.
create synonym emp for scott.emp
It shows some error object already exist
Then I tried
create public synonym emp for scott.emp.
And, got same error. So, anyone please share some knowledge on Synonyms. Can we create synonyms with same name in same schema ?
You can have:
Table and Public Synonym with the same name
Public Synonym and Private Synonym with the same name
But can not have:
Table and Private Synonym with the same name inside the same schema
The first thing to note is that Public Synonyms are non-schema objects, while Private Synonyms and Tables are. Another is that the uniqueness of database objects' names are defined by the namespace. As it is stated in SQL Expert Study Guide:
USER, ROLE, and PUBLIC SYNONYM objects are in their own collective namespace.
TABLE, VIEW, SEQUENCE, PRIVATE SYNONYM, and user-defined TYPE objects have their own unique namespace within a given schema.
INDEX objects have their own namespace within a given schema.
CONSTRAINT objects have their own namespace within a given schema.
So, as long as objects do not share the same namespace you can give them the same names.
Hope this helps.
Public synonyms are non-schema objects, when private synonyms as tables are schema objects.
USER, ROLE and PUBLIC SYNONYM are in their own collective namespace.
TABLE, VIEW, SEQUENCE, PRIVATE SYNONYM have their own unique namespace.
An INDEX has their own unique namespace.
A CONSTRAINT object has their own unique namespace within a given schema
While the objects don't share the same namespace, you can give them the same names.
Remember, that you can have:
a table and public synonym with the same name
a public synonym and a private synonym with same name
You cannot have:
a table and a private synonym with the same name inside the same schema.