Skip to Main Content
  • Questions
  • Can I call a database link over a database link?

Breadcrumb

May 4th

Question and Answer

Tom Kyte

Thanks for the question, Duke.

Asked: February 27, 2008 - 6:19 am UTC

Last updated: February 27, 2008 - 1:31 pm UTC

Version: 10.2.0.1

Viewed 1000+ times

You Asked

We've got our primary Oracle data warehouse running on *NIX, and a second one on Windows; both on our LAN. I've configured Heterogeneous Services / ODBC connections on the *dows database to various foreign databases (Informix, DB2, SQL Server).

Since I normally pull data from a fixed set of foreign tables (typically one schema per foreign database), I've got a schema per foreign database on the Windows database. For example, called VIEWDB2. In those schemas, I set up views on the foreign database, e.g.:
CREATE VIEW polqte AS SELECT * FROM ciopdba.polqte@DB2;
Similarly on the main database, I've got similarly-named schemas per foreign database that point to the views on the Windows database.
CREATE VIEW polqte AS SELECT * FROM viewdb2.polqte@Oracle_on_windows;
So on our main *NIX database (or on the Windows database), I can access, say, the DB2 database simply as:
SELECT * FROM viewdb2.polqte;

Sometimes though I'd like to write ad hoc queries against a foreign database. Is there any way of writing a query like this (from *NIX?)
SELECT * FROM ciopdba.polqte@db2@oracle_on_windows
? Or do we just log onto the Oracle_on_windows and write the ad hocs there?

Thank you.

and Tom said...

No, the database links go one level only. In fact a valid database link name is "x@y" - the @ in the name is used for database link qualification in the single instance. Useful for loopback links with global names:

ops$tkyte%ORA10GR2> create database link loopback@ora10gr2 connect to ops$tkyte identified by foobar using 'ora10gr2';

Database link created.

ops$tkyte%ORA10GR2> select * from dual@loopback@ora10gr2;

D
-
X

ops$tkyte%ORA10GR2> create database link loopback connect to ops$tkyte identified by foobar using 'ora10gr2';

Database link created.


ops$tkyte%ORA10GR2> select * from dual@loopback;
select * from dual@loopback
                   *
ERROR at line 1:
ORA-02085: database link LOOPBACK.REGRESS.RDBMS.DEV.US.ORACLE.COM connects to
ORA10GR2.REGRESS.RDBMS.DEV.US.ORACLE.COM



that said, you can "ad hoc" any of your existing views, for example:

SELECT * FROM ciopdba.polqte@db2@oracle_on_windows

would just be

SELECT * FROM viewdb2.polqte@Oracle_on_windows;

you don't need to log into windows for that.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

rationale for ad hoc

Duke Ganote, March 03, 2008 - 1:45 pm UTC

For my product *IX link-to-HS-link-to-production DB2, it's easy enough to build views for all the production tables. They're fixed, and in one schema.

However, for our test *IX database, it points to a test/dev DB2 database where one schema is 'as is' database, another is 'to be next release' with a few more columns on some tables, and so forth. Those are the ones where it would be more convenient to allow the developers to ad-hoc against any DB2 schema from *IX, rather than logging into the Wind'Oracle database to run ad hocs against DB2.

I suppose I could build (there's no overlap in schema namespace) schemas on the HS database for all of the dozen or so DB2 dev/test schemas, and overnightly rebuild views so they'd capture any overnightly changes to the DB2 schemas, yet still be ad hoc accessible to the deveopers from Oracle on *IX.

More to Explore

Multitenant

Need more information on Multitenant? Check out the Multitenant docs for the Oracle Database