python連接數(shù)據(jù)庫(kù)oracle PYTHON3連接ORACLE數(shù)據(jù)庫(kù)?
PYTHON3連接ORACLE數(shù)據(jù)庫(kù)?謝謝邀請(qǐng)!cx_Oracle是一個(gè)Python擴(kuò)展模塊,可以用來(lái)訪問(wèn)Oracle數(shù)據(jù)庫(kù)。cx_Oracle 6已經(jīng)用Python 2.7版本以及3.4及更高版本進(jìn)
PYTHON3連接ORACLE數(shù)據(jù)庫(kù)?
謝謝邀請(qǐng)!cx_Oracle是一個(gè)Python擴(kuò)展模塊,可以用來(lái)訪問(wèn)Oracle數(shù)據(jù)庫(kù)。
cx_Oracle 6已經(jīng)用Python 2.7版本以及3.4及更高版本進(jìn)行了測(cè)試。 您可以使用Oracle 11.2,12.1和12.2客戶端庫(kù)的cx_Oracle。 Oracle的標(biāo)準(zhǔn)客戶端 - 服務(wù)器版本互操作性允許連接到較舊和較新的數(shù)據(jù)庫(kù)。 例如,Oracle 12.2客戶端庫(kù)可以連接到Oracle Database 11.2。
對(duì)于您提到的python3沒(méi)找到對(duì)應(yīng)的教程,您可以去CSND、博客園這類博客進(jìn)行相關(guān)的查找,希望能夠幫助到您!
python3.6連接oracle后怎么讀取數(shù)據(jù)和列名?
def query(self, sql):connect = self.connect()cur = connect.cursor()cur.execute(sql)index = cur.descriptionresult = []for res in cur.fetchall():row = {}for i in range(len(index)-1):row[index[i][0]] = res[i]result.append(row)connect.close()return result這個(gè)方法返回查詢結(jié)果就是帶字段名的{‘字段名’:‘值’}
如何使用Python連接Oracle數(shù)據(jù)庫(kù)?
下載cx_Oracle,下載之后就可以使用了。
簡(jiǎn)單的使用流程如下:
1.引用模塊cx_Oracle2.連接數(shù)據(jù)庫(kù)3.獲取cursor4.使用cursor進(jìn)行各種操作5.關(guān)閉cursor6.關(guān)閉連接
參考代碼:
import cx_Oracle #引用模塊cx_Oracleconn=cx_Oracle.connect("load/123456@localhost/ora11g") #連接數(shù)據(jù)庫(kù)c=conn.cursor() #獲取cursorx=c.execute("select sysdate from dual") #使用cursor進(jìn)行各種操作x.fetchone()c.close() #關(guān)閉cursorconn.close() #關(guān)閉連接
python3.6cx_oracle連接數(shù)據(jù)庫(kù)報(bào)編碼錯(cuò)UnicodeDecodeError?
我說(shuō)下我遇到的情況數(shù)據(jù)庫(kù)字符集是 ZHS16GBK錯(cuò)誤的情況是UnicodeDecodeError: "gbk" codec can"t decode byte 0xa7 in position 12: illegal multibyte sequence經(jīng)過(guò)檢查,在fetchall()獲取記錄時(shí),查詢到的記錄里面有亂碼(應(yīng)該是不包含在數(shù)據(jù)庫(kù)現(xiàn)有字符集下的字符)臨時(shí)的一個(gè)解決辦法是db=cx_Oracle.connect(dblink,encoding="UTF-8")這樣可以讀取了,讀取到的內(nèi)容為廣州市同泰路
如何使用Python連接Oracle數(shù)據(jù)庫(kù)?
在保證python和oralce數(shù)據(jù)庫(kù)已經(jīng)安裝,并運(yùn)行.安裝cx_Oracle
以下是測(cè)試連接oracle數(shù)據(jù)庫(kù)
import cx_Oracle# db=cx_Oracle.connect("user","pass","127.0.0.1")db=cx_Oracle.connect("system/oracle@localhost")print(db.version)db.close()
oracle連接報(bào)錯(cuò)?
我也沒(méi)有找到,目測(cè)是cx_oracle不兼容win10的版本問(wèn)題我安裝的anaconda,python3.6,cx_oracle版本6.0.2就報(bào)這個(gè)錯(cuò)。但是我卸載裝了cx_oracle6.1就沒(méi)問(wèn)題了。應(yīng)該是oracle官方修復(fù)了這個(gè)bug
python使用cx_oracle連接oracle請(qǐng)教?
python 使用cx_oracle連接oracle請(qǐng)教
找到原因了,
原因是由于oracle客戶端的dll與打包的dll不一致,