python使用 cx_Oracle 模塊進行查詢操作示例
本文實例講述了python使用 cx_Oracle 模塊進行查詢操作。分享給大家供大家參考,具體如下:
# !/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: 連接超時
<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常見數(shù)據(jù)庫操作技巧匯總》、《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
Python入門之實例方法、類方法和靜態(tài)方法的區(qū)別講解
這篇文章主要介紹了Python入門之實例方法、類方法和靜態(tài)方法的區(qū)別講解,實例方法是在創(chuàng)建了類的實例之后才能被調(diào)用的方法,類方法是在不需要創(chuàng)建類的實例的情況下就可以調(diào)用的方法,最后,靜態(tài)方法是與類和類的實例都沒有綁定關(guān)系的方法,需要的朋友可以參考下2023-10-10python檢查目錄文件權(quán)限并修改目錄文件權(quán)限的操作
這篇文章主要介紹了python檢查目錄文件權(quán)限并修改目錄文件權(quán)限的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Python中的shutil標(biāo)準(zhǔn)庫用法解析
這篇文章主要介紹了Python中的shutil標(biāo)準(zhǔn)庫用法解析,shutil模塊提供了許多關(guān)于文件和文件集合的高級操作,特別提供了支持文件復(fù)制和刪除的功能,需要的朋友可以參考下2023-09-09pandas滑動窗口學(xué)習(xí)筆記(shift, diff, pct_change)
pandas中有3類窗口,分別是滑動窗口rolling?、擴張窗口expanding以及指數(shù)加權(quán)窗口ewm,下面就來詳細的介紹一下這三種的用法,感興趣的可以了解一下2024-03-03pandas 使用apply同時處理兩列數(shù)據(jù)的方法
下面小編就為大家分享一篇pandas 使用apply同時處理兩列數(shù)據(jù)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-04-04