Solved

Run a script on TOAD SQL editor that pulls data from several DBs

Posted on 2007-11-17
7
4,172 Views
Last Modified: 2013-12-07
I've opened several connections to various dbs in toad. i was trying to write a pl/sql in an editor session opened on one oracle db connection and would like to incorporate data from an oracle db on another connection.
Example:
select db1field
from db1.db1table1
where  fieldA = (select max(db2field) from db2.db2table)

When i run it i get - "table or view does not exist". Is there a sytanx/method for such things?
Thanks!

0
Comment
Question by:Algorithmix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20305509
assuming that db1 and db2 where database links, in oracle you specify them like this:

select db1field
from db1table1@db1 
where  fieldA = (select max(db2field) from db2table@db2)

Open in new window

0
 
LVL 8

Expert Comment

by:LindaC
ID: 20305837
Also if you have created your database link with another schema that is not the owner of the table and has been granted select privilege on that table but there is no synonym, then you must specify the owner of the table like this:

select dblfield from owner.dbltable@db1 where filedA = (select max(db2field) from owner.db2table@db2

Otherwise in the remote db you must grant select privilege on the table and also create a private synonym or a public synonym.
0
 
LVL 11

Accepted Solution

by:
Akenathon earned 500 total points
ID: 20306165
You cannot make one connection use data from another connection, it's not TOAD's limitation, you cannot do that with any DB connection.

Supposing you are connected to db1, the syntax you are looking for is down there, where:
- "public" means anybody can use the connection to db2. If not specified, it's private to the username you are connected with
- connect to etc. describes the username/password to connect to db2. If not specified, the same username and password that you used to connect to db1 in the first place will be tried for db2
- db2_tnsnames_alias is the tnsnames.ora entry name, i.e. what you put to connect to db2: sqlplus username/password@db2_tnsnames_alias

create [public] database link db2
[connect to <db2username> identified by <db2password>] using 'db2_tnsnames_alias';
 
select db1field
from db1.db1table1 
where  fieldA = (select max(db2field) from db2table@db2);

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Algorithmix
ID: 20306799
That's surely the way to do it Akenathon but I guess I don't have creat link privs. Is there a script I can write to list available public links..if any?
Thanks for your solution.
0
 
LVL 11

Expert Comment

by:Akenathon
ID: 20307239
Sure, look at all_db_links to see the ones you can use, and dba_db_links to see all of them. You need to have CREATE DATABASE LINK and/or CREATE PUBLIC DATABASE LINK privileges to add to the list :-)
0
 

Author Comment

by:Algorithmix
ID: 20308629
Great thanks...err...how would I go about viewing the tnsnames.ora?
0
 
LVL 11

Expert Comment

by:Akenathon
ID: 20309802
You'll need to look below $ORACLE_HOME/network/admin (net80/admin if you're on v8), where $ORACLE_HOME stands for "wherever it is that you placed the installation". Just perform an OS find, you can't miss it...

Now, you can avoid messing with it: just use the network configuration assistant, it will let you look and update the thing in a supposedly nicer GUI environment... and TOAD itself has a "tnsnames editor" too!

Friendly advice: if you intend to mess with Oracle any further, read through the concepts manual as soon as you possibly can ;-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  â€¦
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question