Solved

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

Posted on 2007-11-17
7
4,166 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle RMAN - trying to duplicate a database 5 52
setting local variables in a cursor block 3 30
Excess Redo 3 32
Oracle programming for starter 14 37
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

730 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