Querying remote database via database link

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

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?
Question by:YZlat
  • 3
  • 2
LVL 34

Assisted Solution

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
LVL 35

Author Comment

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?
LVL 34

Expert Comment

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


Accepted Solution

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.
LVL 35

Author Comment

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?
LVL 35

Author Comment

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!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now