0

I want to make a query to two different data databases in ORACLE.

What I tried so far is:

select * 
from puigmal_admin.dba.rf_md_sectors C 
  left join puigmal_cad_admin.dba.a3tsec5_plp A on A.cadena = C.codi_sect;
5
  • That is not possible in Oracle, you need to create a dblink Commented Jan 28, 2020 at 11:59
  • I guess yo uare getting confused between Databases and servers. You can communicate between databases but not with 2 servers without DBlink. Commented Jan 28, 2020 at 12:01
  • @AnkitBajpai - 1, 2, more, servers is irrelevent. If you want to select from multiple databases in Oracle,a database link is needed. Period. Full stop. It doesn't make any difference what servers those databases reside on. Commented Jan 28, 2020 at 12:45
  • @EdStevens, I beg to differ. In Oracle, DBs are usually users. You can access one users table from another user or DB if they are on same server. Commented Jan 28, 2020 at 12:58
  • @AnkitBajpai - what you describe is MSSQL architecture. Not Oracle. In oracle "database" most definitely does NOT equal "user". You need to review the Oracle Concepts. Commented Jan 28, 2020 at 14:43

1 Answer 1

2

What do you call a "database"? I'm asking because people - whose background is not Oracle - tend to mix oracle "users" (schemas) with "databases".


If tables involved in query belong to users that reside in the same database, it is enough to grant (select) privilege from one user to another.

connect scott/tiger
grant select on emp to mike;

connect mike/lion

select d.dname, e.ename
from dept d join scott.emp e on e.deptno = d.deptno
                 ^^^^^^^^^
                 this is a table that belongs to SCOTT who granted you SELECT privilege

If they belong to users that reside in different databases, then you need a database link.

connect mike/lion

create database link dbl_scott
connect to scott
identified by tiger
using 'orcl';

select d.dname, e.ename
from dept d join emp@dbl_scott e on e.deptno = d.deptno;
                 ^^^^^^^^^^^^^
                 this is a table you're accessing over the database link
Sign up to request clarification or add additional context in comments.

2 Comments

What do you exactly mean by users that reside in different databases? Coz as far as i know users and databases are same in Oracle. Is there something else also?
In Oracle, user is not the same as the database, @Ankit. A database can contain many users (every user owns its own schema whose name is equal to user's name). Read database concepts, docs.oracle.com/en/database/oracle/oracle-database/19/cncpt/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.