python使用 cx_Oracle 模塊進(jìn)行查詢操作示例
本文實(shí)例講述了python使用 cx_Oracle 模塊進(jìn)行查詢操作。分享給大家供大家參考,具體如下:
# !/usr/bin/env python # -*- coding: utf-8 -*- import cx_Oracle from pprint import pprint import csv import time import re import binascii print time.ctime() try: conn = cx_Oracle.connect('tlcbuser/tlcbuser@10.5.100.232/tlyy') # cursor = conn.cursor() # xsql="select * from tlcb_mon_device a where a.ipaddr='10.3.244.1'" # r = cursor.execute(xsql) # print r except Exception,e: print e print type(e) print str(e).decode('UTF-8').encode('GBK') print time.ctime()
C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/a6.py
Mon Oct 22 10:35:59 2018
ORA-12170: TNS: ���ӳ�ʱ
<class 'cx_Oracle.DatabaseError'>
Mon Oct 22 10:36:20 2018
Process finished with exit code 0
# !/usr/bin/env python # -*- coding: utf-8 -*- import cx_Oracle from pprint import pprint import csv import time import re import binascii import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' print time.ctime() try: conn = cx_Oracle.connect('tlcbuser/tlcbuser@10.5.100.232/tlyy') # cursor = conn.cursor() # xsql="select * from tlcb_mon_device a where a.ipaddr='10.3.244.1'" # r = cursor.execute(xsql) # print r except Exception,e: print e print type(e) print time.ctime()
C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/a6.py
Mon Oct 22 10:44:20 2018
ORA-12170: TNS: 連接超時(shí)
<class 'cx_Oracle.DatabaseError'>
Mon Oct 22 10:44:41 2018
Process finished with exit code 0
# !/usr/bin/env python # -*- coding: utf-8 -*- import cx_Oracle from pprint import pprint import csv import time import re import binascii import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' print time.ctime() conn = cx_Oracle.connect('test/test@10.10.17.200/serv') cursor = conn.cursor() xsql="select 'aaa' from dual" cursor.execute(xsql) result = cursor.fetchall() print result
C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/rizhiyi/a7.py
Mon Oct 22 11:33:52 2018
[('aaa',)]
Process finished with exit code 0
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
Python入門之實(shí)例方法、類方法和靜態(tài)方法的區(qū)別講解
這篇文章主要介紹了Python入門之實(shí)例方法、類方法和靜態(tài)方法的區(qū)別講解,實(shí)例方法是在創(chuàng)建了類的實(shí)例之后才能被調(diào)用的方法,類方法是在不需要?jiǎng)?chuàng)建類的實(shí)例的情況下就可以調(diào)用的方法,最后,靜態(tài)方法是與類和類的實(shí)例都沒(méi)有綁定關(guān)系的方法,需要的朋友可以參考下2023-10-10pandas 像SQL一樣使用WHERE IN查詢條件說(shuō)明
這篇文章主要介紹了pandas 像SQL一樣使用WHERE IN查詢條件說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06python檢查目錄文件權(quán)限并修改目錄文件權(quán)限的操作
這篇文章主要介紹了python檢查目錄文件權(quán)限并修改目錄文件權(quán)限的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03Python中的shutil標(biāo)準(zhǔn)庫(kù)用法解析
這篇文章主要介紹了Python中的shutil標(biāo)準(zhǔn)庫(kù)用法解析,shutil模塊提供了許多關(guān)于文件和文件集合的高級(jí)操作,特別提供了支持文件復(fù)制和刪除的功能,需要的朋友可以參考下2023-09-09pandas滑動(dòng)窗口學(xué)習(xí)筆記(shift, diff, pct_change)
pandas中有3類窗口,分別是滑動(dòng)窗口rolling?、擴(kuò)張窗口expanding以及指數(shù)加權(quán)窗口ewm,下面就來(lái)詳細(xì)的介紹一下這三種的用法,感興趣的可以了解一下2024-03-03詳解pyqt5 動(dòng)畫(huà)在QThread線程中無(wú)法運(yùn)行問(wèn)題
這篇文章主要介紹了詳解pyqt5 動(dòng)畫(huà)在QThread線程中無(wú)法運(yùn)行問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05pandas 使用apply同時(shí)處理兩列數(shù)據(jù)的方法
下面小編就為大家分享一篇pandas 使用apply同時(shí)處理兩列數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-04-04在Pandas?DataFrame中插入一列的方法實(shí)例
在敲代碼的過(guò)程中,老是會(huì)遇到在Dataframe中新添加一列的情況,所以下面這篇文章主要給大家介紹了關(guān)于如何在Pandas?DataFrame中插入一列的方法實(shí)的相關(guān)資料,需要的朋友可以參考下2022-03-03