python使用 cx_Oracle 模块进行查询操作示例

作者:zhaoyangjian724 时间:2022-06-17 05:55:24 

本文实例讲述了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

希望本文所述对大家Python程序设计有所帮助。

来源:https://blog.csdn.net/zhaoyangjian724/article/details/83271545

标签:python,cx,Oracle,查询
0
投稿

猜你喜欢

  • Python OpenCV超详细讲解基本功能

    2021-04-26 11:47:36
  • Python抓取手机号归属地信息示例代码

    2023-03-02 21:24:59
  • Dreamweaver技巧50问

    2008-10-16 14:00:00
  • PHP和JS之间的数据交互并处理

    2023-05-25 00:57:08
  • 如何实现让每句话的头一个字母都大写?

    2010-05-24 18:26:00
  • “验证码”等于“流氓软件”

    2007-10-19 18:29:00
  • 用于WebKit的CSS诀窍[译]

    2009-03-11 20:03:00
  • MySQL数据库的其它安全问题

    2008-12-23 15:40:00
  • pandas 使用apply同时处理两列数据的方法

    2021-09-27 07:35:30
  • 详解python pandas 分组统计的方法

    2021-01-30 05:33:48
  • pygame游戏之旅 添加碰撞效果的方法

    2022-11-04 06:45:46
  • [译]2009年海外Web设计风潮(下)

    2009-01-23 09:34:00
  • python数据可视化绘制火山图示例

    2022-05-08 03:47:56
  • 教你快速掌握一些方便易用的SQL语句

    2008-11-28 15:21:00
  • 适合各种浏览器的js拖动层

    2007-10-22 22:43:00
  • python有几个版本

    2021-09-12 00:44:30
  • python将音频进行变速的操作方法

    2023-10-05 19:04:34
  • VMware中Linux共享mysql数据库

    2010-10-25 20:29:00
  • python 中文件输入输出及os模块对文件系统的操作方法

    2023-04-10 18:34:05
  • 用asp实现读取文件的最后一行的代码

    2011-03-08 10:55:00
  • asp之家 网络编程 m.aspxhome.com