Step python connect to Oracle

1, the installation cx_Oracle

pip install cx_Oracle

2, the configuration oci.dll oraociei11.dll added to the variable path environment

 

 Download: Baidu search download, Oracle PLSQL download

3, connecting step

# coding:utf-8

import pandas as pd

import sys
import codecs
#sys.stdout = codecs.getwriter("gbk")(sys.stdout.detach())

from sqlalchemy import create_engine

import cx_Oracle

#db=cx_Oracle.connect('admin','admin','172.16.1.452:1521/orcl')
db=cx_Oracle.connect('你的账号','密码','IP:端口/服务名')
print (db.version)

cr=db.cursor()

SQL2 = '''SELECT * FROM OA_W_BAOXIAOMXYWB'''

cr.execute(SQL1)

rs=cr.fetchall()

zz=pd.DataFrame(rs)

print (zz)

db.close()

 

Guess you like

Origin www.cnblogs.com/wuzaipei/p/11594243.html