cx_Oracle Get Boolean Return Value(CX_ORACLE获取布尔返回值)
本文介绍了CX_ORACLE获取布尔返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我整天都在努力工作,试图使用CX_ORACLE从PL/SQL函数获取布尔值。我见过一些帖子讨论使用其他数据类型(如char或整数)来存储返回值,但当我尝试使用这种解决方案时,我得到了一个不正确的数据类型错误。首先,让我展示一下代码。
def lives_on_campus(self):
cursor = conn.cursor()
ret = cursor.callfunc('students_api.lives_on_campus', bool, [self.pidm])
return ret
如果我使用11.2.0.4数据库客户端,则会出现以下错误。
File "student-extracts.py", line 134, in <module>
if student.lives_on_campus():
File "student-extracts.py", line 58, in lives_on_campus
ret = cursor.callfunc('students_api.lives_on_campus', bool, [self.pidm])
cx_Oracle.DatabaseError: DPI-1050: Oracle Client library is at version 11.2 but version 12.1 or higher is needed
如果我使用12.1.0.2或更高版本的数据库客户端,则会出现此错误。
Traceback (most recent call last):
File "student-extracts.py", line 134, in <module>
if student.lives_on_campus():
File "student-extracts.py", line 58, in lives_on_campus
ret = cursor.callfunc('students_api.lives_on_campus', bool, [self.pidm])
cx_Oracle.DatabaseError: ORA-03115: unsupported network datatype or representation
基本上,无论我使用哪个版本的SQL客户端,它都会出错。现在,我知道如果数据库版本是12c R2,上面的代码就可以工作了。遗憾的是,我们的测试环境中只有该版本,并且Prod只使用11g数据库。有没有什么我可以让这个功能在11G数据库上工作的方法?必须有解决办法。
~Bob
推荐答案
尝试包装匿名块:
with connection.cursor() as cursor:
outVal = cursor.var(int)
sql="""
begin
:outVal := sys.diutil.bool_to_int(students_api.lives_on_campus(:pidm));
end;
"""
cursor.execute(sql, outVal=outVal, pidm='123456')
print(outVal.getvalue())
这篇关于CX_ORACLE获取布尔返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:CX_ORACLE获取布尔返回值
基础教程推荐
猜你喜欢
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
