Oracle schema table reference a.b@c.d.e aliasRefForMe
- what is this?
Not sure what this means for an Oracle select statement. Anybody know?
Select Distinct aliasRefForMe.field1 From a.b@a.c.d aliasRefForMe
Two questions:
Does
Select ... From a.b.c
mean a schema and a sub schema before the table in Oracle? Do sub schemas even exist?What is the @ for in a.b@a.c.d aliasRefForMe?
Note that I changed the table/schema names for company privacy.
The '@' is a dblink in oracle
The format of which is:
The Oracle documentation includes a section on Syntax for Schema Objects and Parts in SQL Statements.
So in your example
@a.c.d
is a database link, where thea
part is the remote database name and thec.d
is the database domain - possibly either a machine name and/or your company domain. Read more about database links and global database names and how they are formed.a
is the name of a schema on the remote database the link is pointing to.b
is the name of a table in that schema on the remote database.aliasRefForMe
is a table alias (or correlation name), which is just to make it easier to refer to that table elsewhere in your query.field1
is the name of a column in that table on the remote database.Without the table alias the query would be:
... which in this contrived example is actually shorter, but with real object names would be longer than the original, and harder to read and understand. Although in this case, with only a single table being queried, you could get away with just:
as there is no ambiguity about where
field1
is coming from; but qualifying everything is a good habit as it saves time and confusion later.Table aliases are even more useful when there are multiple tables with long names - they make both the select list and join conditions shorter. It helps if the aliases are meaningful names though.