python之cx_oracle模块

cx_oracle模块主要用于python与oracle交互,可以从数据库中检索到数据等,返回元祖数据(有待验证)

1、安装该模块,根据自己的操作系统及安装的Py版本及位数,在网站上下载对应的版本cx_oracle模块,安装可能会遇到各种问题,

在网上搜搜就可以解决,我目前安装的是py3.3_32位,对应cx_oracle是cx_Oracle-5.1.2-10g.win32-py3.3.msi

2、使用示例

 1 import cx_Oracle
 2 a=[]
 3 conn = cx_Oracle.connect('sys/orcl@192.168.1.120/ORTEST',mode=cx_Oracle.SYSDBA)
 4 curs = conn.cursor()
 5 sql = 'select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024   "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"  from  (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name)   a,  (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name)   b  where   a.tablespace_name=b.tablespace_name  order   by   ((a.bytes-b.bytes)/a.bytes)   desc '
 6 curs.execute(sql)
 7 print("检查数据库表空间使用情况---------------------")
 8 print("TABLESPACE_NAME    Sum MB    used MB    free MB    percent_used")
 9 for result in curs:
10     print(result)
11     a.append(result)
12 curs.close()
13 conn.close()
14 print (a )
View Code

 row=curs.fetchall() 

return row也可以实现结果,如上用for 遍历

posted on 2020-08-26 21:32  小杜的学习天地  阅读(203)  评论(0编辑  收藏  举报

导航