用cx_Oracle调用存储过程(入参,出参,返回游标)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# -*- coding: utf-8 -*- import cx_Oracle import datetime import os #设置中文环境 os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' #连接ORACLE数据库 DB=cx_Oracle.connect('sys_monitor','sys_monitor','10.10.10.10:1521/orcl') print DB.dsn print DB.version #创建游标 cursor = DB.cursor() #定义入参 a_d_bdate = datetime.datetime.strptime('2022-12-01','%Y-%m-%d') a_d_edate = datetime.datetime.strptime('2022-12-31','%Y-%m-%d') a_vc_qsxw = 'qs_24' #pic_data = cx_Oracle.Binary(data) #准备出参 out_code = cursor.var(cx_Oracle.NUMBER) out_str = cursor.var(cx_Oracle.STRING) out_cursor = cursor.var(cx_Oracle.CURSOR) #调用存储过程 data=cursor.callproc('testdb.sp_rpt',(0, a_d_bdate, a_d_edate, a_vc_qsxw , out_code, out_str, out_cursor)) #cursor.execute('commit') v_cursor = out_cursor.getvalue() for c in v_cursor : print(c) #关闭清理 cursor.close() DB.close() |
分类: oracle