0

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer. I thought exactly like you claimed, but server that I try to connect is not mine, it is someone else's. He claimed that I can connect to view without actually connecting to db, so I tried it. ;)
I'd prefer to call a view a "stored query" rather than a "virtual table".
So would I - but in terms of explaining to the OP, given his question, the latter term seemed the better to clarify things to me.

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.