Solved

Querying remote database via database link

Posted on 2013-06-03
6
427 Views
Last Modified: 2013-06-04
I need to get data from RemoteDB1 while I am logged in to SourceDB. I found that there are two database links previously created on SourceDB to RemoteDB1, called SourceDB_TO_RemoteDB and RemoteDB.

When I queried dba_db_links, I saw that OWNER for both links is PUBLIC, and username for both links is RemoteDB (same as the GLOBAL_NAME in the RemoteDB).

RemoteDB user does not exist in RemoteDB1 but not in SourceDB.

Now I also have user RPT in RemoteDB1 database that has a view in its schema Main_view. Main_view was created on a couple of catalog views that user RPT has SELECT privileges on.

SourceDB also has a user RPT created.

I was trying to use datbase link RemoteDB while logged in to the SourceDB to access Main_view in RPT user schema:

SELECT FIELD1 "Field 1", FIELD2 "Field 2"
FROM Main_view@RemoteDB
WHERE START_TIME > SYSDATE-1
AND FIELD3='Open'
ORDER BY FIELD1;

I get an error

ERROR at line 2:
ORA-00942: table or view does not exist
ORA-02063: preceding line from RemoteDB

I have gotten this error both, while logged in as RPT user and as SYS user.

Can someone help me to query data from RemoteDB1?
0
Comment
Question by:YZlat
  • 3
  • 2
6 Comments
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 250 total points
ID: 39217290
The error would indicate that the either the user that is connecting to the remote db doesn't have privileges, or you are using an incorrect name.

What happens if you try:

SELECT FIELD1 "Field 1", FIELD2 "Field 2"
FROM RPT.Main_view@RemoteDB
WHERE START_TIME > SYSDATE-1
AND FIELD3='Open'
ORDER BY FIELD1;
0
 
LVL 35

Author Comment

by:YZlat
ID: 39217307
I tried that and gotten the same error.

I was wondering how would I give the user on SourceDB priveleges on a view on RemotDB1?
0
 
LVL 34

Expert Comment

by:johnsone
ID: 39217333
The user on SourceDB doesn't need privileges on RemotDB1.  The user that the database link connects as in RemotDB1 needs the privilege.  My guess is that you need to connect to RemotDB1 and grant privileges on the view you are trying to select from (RPT.MAIN_VIEW) to the user the link is connecting as.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 7

Accepted Solution

by:
Docteur_Z earned 250 total points
ID: 39218480
Yous wrote
RemoteDB user does not exist in RemoteDB1 but not in SourceDB.
I guess you've ment "RemoteDB user does exist in RemoteDB1 but not in SourceDB."

So your issue is that this RemoteDB  user doesn't have the necessary grants on the view you want to query (RPT.MAIN_VIEW). So all the tables underlying this view.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39218808
Docteur_Z, yes that's the issue. I did grant the RemoteDB user on the Main_view but still no difference.

What I found is that the underlying view for Main_view is a nother view that is in RemoteDB user's schema. Shouldn't RemoteDB user have privileges then?
0
 
LVL 35

Author Comment

by:YZlat
ID: 39218820
Got it!

I needed to do two things:

1) Grant SELECT permissions on Main_view to RemoteDB user
2) Perfix Main_view name with schema name when querying from SourceDB

Thanks guys!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

777 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