Rules for Name Resolution in SQL Statements
An object name takes the following form:
[schema.]name[@database]
Some examples include:
Emp_tab
Scott.Emp_tab
Scott.Emp_tab@Personnel
A session is established when a user logs onto a database. Object names are resolved relative to the current user session. The username of the current user is the default schema. The database to which the user has directly logged-on is the default database.
Oracle has separate namespaces for different classes of objects. All objects in the same namespace must have distinct names, but two objects in different namespaces can have the same name. Tables, views, snapshots, sequences, synonyms, procedures, functions, and packages are in a single namespace. Triggers, indexes, and clusters each have their own individual namespace. For example, there can be a table, trigger, and index all named SCOTT.EMP_TAB.
Based on the context of an object name, Oracle searches the appropriate namespace when resolving the name to an object. For example, in the following statement:
DROP CLUSTER Test
Oracle looks up TEST in the cluster namespace.
Rather than supplying an object name directly, you can also refer to an object using a synonym. A private synonym name has the same syntax as an ordinary object name. A public synonym is implicitly in the PUBLIC schema, but users cannot explicitly qualify a synonym with the schema PUBLIC.
Synonyms can only be used to reference objects in the same namespace as tables. Due to the possibility of synonyms, the following rules are used to resolve a name in a context that requires an object in the table namespace:
Look up the name in the table namespace.
1.
If the name resolves to an object that is not a synonym, then no further work is necessary.
2. If the name resolves to a private synonym, then replace the name with the definition of the synonym and return to step 1.
3. If the name was originally qualified with a schema, then return an error; otherwise, check if the name is a public synonym.
4. If the name is not a public synonym, return an error; otherwise, then replace the name with the definition of the public synonym and return to step 1.
Partager