Python 连接 Oracle
首先安装驱动: pip install xc_Oracle
import cx_Oracle
conn = cx_Oracle.connect('user/password@DB') # localhost则忽略,直接使用 DB Name
c = conn.cursor()
x = c.execute('select * from newsadmin.a') #执行 sql 查询
rs = x.fetchall() # 结果集 ResultSet
c.close() #关闭
conn.close()
for x in rs: # 输出
print(x)
输出结果集:
网友评论