I am trying to understand a query . When I run the below query , no rows are fetched.
select * from Table
But when I run the query , a result is returned having multiple rows.
select * from Table@somestring
I am not sure what @ followed by somestring means and why that is used in PL/SQL.
Best Answer
It's part of a distributed query. The string after the
@
is a database link.You can see where the database link is pointing by querying the
all_db_links
view, or theuser_
ordba_
equivalents depending on the owner and your privileges. It might refer to a TNS alias, in which case you could get further details from thetnsnames.ora
file.When you query
table
you're (usually) looking at a table in your own schema. When you querytable@dblink
you're looking at a table in a remote database. They are different objects so you'd expect different results. Your local table is empty, but the remote one has some data.I say 'usually' because
table
could be a synonym pointing at another schema, or even to a schema on a remote database itself. Anddblink
could be pointing back to your own database - it would be unusual but I've seen it done as a way of accessing another schema (not something I'd recommend). Without seeing if there is a synonym or where thedblink
is going it's hard to be definitive, but these are less common scenarios. In this case though you're clearly hitting two different tables, probably on different databases. (Well, unless there's a VPD and connecting to the same table as a different user gives a different view... but starting to go down the rabbit hole now...)