9394952

导航

用cx_Oracle调用存储过程(入参,出参,返回游标)的笔记

参考文档:

https://www.ssfiction.com/sqljc/801062.html

https://blog.csdn.net/qq_39065491/article/details/128021937

https://blog.csdn.net/bullswu/article/details/7372482

https://www.jb51.cc/python/3584841.html

 

# -*- 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()

 

posted on 2023-01-13 14:52  9394952  阅读(411)  评论(0编辑  收藏  举报