简体   繁体   中英

Python connection to Oracle database

I am writing a Python script to fetch and update some data on a remote oracle database from a Linux server. I would like to know how can I connect to remote oracle database from the server.
Do I necessarily need to have an oracle client installed on my server or any connector can be used for the same?
And also if I use cx_Oracle module in Python, is there any dependency that has to be fulfilled for making it work?

You have to Install Instance_client for cx_oracle driver to interact with remote oracle server

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html .

Use SQLAlchemy (Object Relational Mapper) to make the connection and interact with Oracle Database.

The below code you can refer for oracle DB connection.

from sqlalchemy import create_engine

from sqlalchemy.orm import sessionmaker

engine = create_engine('oracle+cx_oracle://test_user:test_user@ORACSG')

session_factory = sessionmaker(bind=engine, autoflush=False)

session = session_factory()

res = session.execute("select * from emp");

print res.fetchall()

Yes, you definitely need to install an Oracle Client, it even says so in cx_oracle readme.txt. Another recommendation you can find there is installing an oracle instant client, which is the minimal installation needed to communicate with Oracle, and is the simplest to use. Other dependencies can usually be found in the readme.txt file, and should be the first place to look for these details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM