Domanda

Can someone give me brief information about how to "connect" to an Oracle view from Python?

I looked around but couldn't anything. I'm new to Oracle DB. I will not use it I will only connect it with Python and get some info. But I have only view to connect to.

At first I thought that I can use view like below, to connect:

db = sqlalchemy.create_engine('oracle://USER:PASS@SERVER:1521/VIEW_NAME')

Then I used this:

cx_Oracle.connect(user='USER', password='PASS',
     dsn=cx_Oracle.makedsn('SERVER',1521,'VIEW_NAME'))

Then I realized that a view cannot be used as DB Name, because it is just a "tool" to only view the existing table(s).

How can I accomplish this?

È stato utile?

Soluzione

A view in an RDBMS like Oracle is essentially a "virtual" table. When querying it, you query it just like you would a table. So connect to the database/schema containing the view, and select from it as usual. The view doesn't feature in the connection details at all, just in the query.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top