共計 491 個字符,預(yù)計需要花費(fèi) 2 分鐘才能閱讀完成。
Python 連接 Oracle 的方法可以使用 cx_Oracle 模塊。
以下是一個 Python 連接 Oracle 數(shù)據(jù)庫的示例代碼:
import cx_Oracle
# 創(chuàng)建連接
connection = cx_Oracle.connect('username', 'password', 'host:port/service_name')
# 創(chuàng)建游標(biāo)
cursor = connection.cursor()
# 執(zhí)行 SQL 查詢
cursor.execute('SELECT * FROM table_name')
# 獲取查詢結(jié)果
result = cursor.fetchall()
# 打印查詢結(jié)果
for row in result:
print(row)
# 關(guān)閉游標(biāo)和連接
cursor.close()
connection.close()
請確保已經(jīng)安裝了 cx_Oracle 模塊,并將示例代碼中的 username
、password
、host:port/service_name
和table_name
替換為實際的數(shù)據(jù)庫信息和查詢語句。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完