新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python怎么連接oracle數(shù)據(jù)庫
python怎么連接Oracle數(shù)據(jù)庫

1、下載cx_Oracle模塊
pip install cx_Oracle
2、編寫Python代碼
import cx_Oracle #引用模塊cx_Oracle
#conn=cx_Oracle.connect(‘用戶名/密碼@主機ip地址:端口號/Service Name(SID)')
conn=cx_Oracle.connect('truck/******@10.74.**.**:****/****') #連接數(shù)據(jù)庫
c=conn.cursor() #獲取cursor
x=c.execute('select sysdate from dual') #使用cursor進行各種操作
x.fetchone()
c.close() #關(guān)閉cursor
conn.close() #關(guān)閉連接正確輸入?yún)?shù)之后,數(shù)據(jù)庫連接成功
3、Python連接Oracle如果有中文,可能會出亂碼,可通過以下方法解決
import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
同時,在Python腳本中,添加一行代碼
# -*- coding: utf-8 -*-
更多技術(shù)請關(guān)注Python視頻教程。
網(wǎng)頁名稱:創(chuàng)新互聯(lián)Python教程:Python怎么連接oracle數(shù)據(jù)庫
URL地址:http://www.dlmjj.cn/article/dpijcic.html


咨詢
建站咨詢
