python網(wǎng)站 如何使用Python連接Oracle數(shù)據(jù)庫?
如何使用Python連接Oracle數(shù)據(jù)庫?在保證python和oralce數(shù)據(jù)庫已經(jīng)安裝,并運(yùn)行.安裝cx_Oracle以下是測試連接oracle數(shù)據(jù)庫import cx_Oracle# db=cx
如何使用Python連接Oracle數(shù)據(jù)庫?
在保證python和oralce數(shù)據(jù)庫已經(jīng)安裝,并運(yùn)行.安裝cx_Oracle
以下是測試連接oracle數(shù)據(jù)庫
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()
Python在日常工作中能用到嗎?
十分有用,比如小編用python 制作了一個BOM管理系統(tǒng),以前做BOM需要一天時間,現(xiàn)在只需要幾秒鐘,這些都是小編學(xué)習(xí)python 以后才能做到,并且python 自學(xué)也不太難,跟著課本或者學(xué)習(xí)教程,自己擼一遍代碼,很容易開發(fā)自己的東西,并應(yīng)用到自己的實(shí)際生活與工作中
{!-- PGC_COMMODITY:{"commodity_id": "3402028863860139304"} --}如何用python讀取oracle數(shù)據(jù)庫?
下載cx_Oracle,下載之后就可以使用了。
簡單的使用流程如下:
1.引用模塊cx_Oracle2.連接數(shù)據(jù)庫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ù)庫c=conn.cursor() #獲取cursorx=c.execute("select sysdate from dual") #使用cursor進(jìn)行各種操作x.fetchone()c.close() #關(guān)閉cursorconn.close() #關(guān)閉連接