[sql] SELECT data from another schema in oracle

I want to execute a query that selects data from a different schema than the one specified in the DB connection (same Oracle server, same database, different schema)

I have an python app talking to an Oracle server. It opens a connection to database (server/schema) A, and executes select queries to tables inside that database.

I've tried the following :

select .... 
from pct.pi_int, pct.pi_ma, pct.pi_es
where ...

But I get:

ORA-00942: table or view does not exist

I've also tried surrounding the schema name with brackets:

from [PCT].pi_int, [PCT].pi_ma, [PCAT].pi_es

I get:

ORA-00903: invalid table name

The queries are executed using the cx_Oracle python module from inside a Django app.

Can this be done or should I make a new db connection?

This question is related to sql oracle cx-oracle

The answer is


Depending on the schema/account you are using to connect to the database, I would suspect you are missing a grant to the account you are using to connect to the database.

Connect as PCT account in the database, then grant the account you are using select access for the table.

grant select on pi_int to Account_used_to_connect

In addition to grants, you can try creating synonyms. It will avoid the need for specifying the table owner schema every time.

From the connecting schema:

CREATE SYNONYM pi_int FOR pct.pi_int;

Then you can query pi_int as:

SELECT * FROM pi_int;