Python 3 ORACLE支持及实例

Python 3 ORACLE支持

anaconda 安装以后,在命令行下执行

pip install cx_Oracle libaio

在程序中

import cx_Oracle

username ="scott" # config.get('default', 'username')

password ="tiger" # config.get('default', 'password')

uri ="localhost" #config.get('default', 'uri')

port ="1521" # config.get('default', 'port')

# Create the connection and setup the cursor

#测试连接字符串

print(f'{username}/{password}@{uri}:{port}/orcl')

conn = cx_Oracle.connect(f'{username}/{password}@{uri}:{port}/orcl')

cur = conn.cursor()

# Execute select statement and fetch all results

#cur.execute("SELECT 'Hello World!' FROM dual")

cur.execute("SELECT * FROM scott.dept")

res = cur.fetchall()

cc=cur.rowcount

print(cc)

for key in res:

print(key)

# Print results

print(res)

#输出Hello World!

print (res[0][0])

print("Hello Anaconda")

# Close the connection

cur.close()

conn.close()

#结果

scott/tiger@localhost:1521/orcl

[('Hello World!',)]

Hello World!

Hello Anaconda

参考:

https://enterprise-docs.anaconda.com/en/latest/data-science-workflows/data/oracle.html

https://cx-oracle.readthedocs.io/en/latest/

你可能感兴趣的:(Python 3 ORACLE支持及实例)