import cx_Oracle
# 建立与 Oracle 数据库的连接
connection = cx_Oracle.connect("{login}/{passwd}@{IP}:{PORT}/{Service Name}")
# 创建游标
cursor = connection.cursor()
# 执行 SQL 查询
cursor.execute("SELECT table_name FROM user_tables")
# 获取查询结果
result = cursor.fetchall()
# 处理查询结果
for row in result:
# 处理每一行数据
print(row)
# 提交事务(如果需要)
connection.commit()
# 关闭游标和数据库连接
cursor.close()
connection.close()
Traceback (most recent call last):
File "~/test_oracle.py", line 4, in <module>
connection = cx_Oracle.connect("xxx/xxx@xxx:xxx/xxx")
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 0x0001): tried: 'libclntsh.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibclntsh.dylib' (no such file), '/Users/py373/lib/libclntsh.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/py373/lib/libclntsh.dylib' (no such file), '/Users/py373/lib/libclntsh.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/py373/lib/libclntsh.dylib' (no such file), '/Users/anaconda". See #macos for help
cd $HOME/Downloads
curl -O https://download.oracle.com/otn_software/mac/instantclient/198000/instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg
hdiutil mount instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg
/Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru/install_ic.sh
hdiutil unmount /Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru
如果对你有所帮助,可以点赞、关注、收藏起来,不然下次就找不到了
【点赞】⭐️⭐️⭐️⭐️⭐️
【关注】⭐️⭐️⭐️⭐️⭐️
【收藏】⭐️⭐️⭐️⭐️⭐️
Thanks for watching.
–Kenny