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
投稿
猜你喜欢
php中instanceof 与 is_a()区别分析
2023-11-19 06:04:56
Python2.6版本中实现字典推导 PEP 274(Dict Comprehensions)
2022-04-13 02:53:50
Flask-Vue前后端分离的全过程讲解
2022-08-07 23:51:11
pandas 对日期类型数据的处理方法详解
2021-12-02 04:43:56
如何删除Git本地仓库和删除GitHub上的Git远程仓库Repository(推荐)
2023-01-30 16:07:59
SSM框架把日志信息保存到数据库过程详解
2024-01-19 12:56:27
设计原则-控件Balloons(气球状提示)
2009-08-15 12:34:00
用Python定时发送天气邮件
2022-09-22 15:11:31
Apifox Echo学习curl httpie 命令使用详解
2022-06-19 22:33:00
tensorflow 获取所有variable或tensor的name示例
2021-04-02 22:29:54
Windows安装Anaconda并且配置国内镜像的详细教程
2023-07-06 13:45:15
python环形单链表的约瑟夫问题详解
2023-03-02 04:13:10
Mysql 5.6添加修改用户名和密码的方法
2024-01-20 09:02:57
Vue + Webpack + Vue-loader学习教程之相关配置篇
2024-04-29 13:10:40
perl产生随机数实现代码
2023-04-14 05:30:10
django foreignkey(外键)的实现
2023-03-15 17:35:51
对vue2.0中.vue文件页面跳转之.$router.push的用法详解
2024-04-30 10:35:03
asp如何自动更新导航栏?
2010-07-07 12:10:00
Python保姆式手把手带你掌握异常的捕获和处理
2022-04-30 14:10:18
Python中类的定义、继承及使用对象实例详解
2023-07-11 17:10:37