Solved

Querying remote database via database link

Posted on 2013-06-03
6
436 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 35

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 35

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
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!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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

735 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