python连接oracle
生活随笔
收集整理的這篇文章主要介紹了
python连接oracle
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python連接oracle需要先根據oracle的版本到網上下載對應版本的instantclient,這個就自己去網上下載了,下載完了解壓到某個文件夾即可。
然后在腳本的最前面加上這句:os.environ['path'] = r'D:\instantclient_12_2' ,路徑就是你存放instantclient的路徑。
之后就可以用python執行oracle數據庫操作了。
import os import cx_Oracleos.environ['path'] = r'D:\instantclient_12_2'conn = cx_Oracle.connect('賬號/密碼@192.168.0.101:1234/某個庫')cursor = conn.cursor()result = cursor.execute("""SELECT count(*) FROM JYSWXF.T_YFJ_NSRMDwhere typ='2' """) #one_data = cursor.fetchone() --取出一條數據 #print(one_data)#many_data = cursor.fetchmany(5) --取出指定條目的數據 #print(many_data)#注意,fetch的三個函數不能同時使用,想要同時使用要多寫幾次cursor.excute() #一般來說,直接使用fetch_all()就可以all_data = cursor.fetchall()print(all_data)cursor.close() conn.close()?
總結
以上是生活随笔為你收集整理的python连接oracle的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python连接阿里云odps
- 下一篇: 用python openpyxl合并多个