Python cx\u Oracle获取布尔返回值

Python cx\u Oracle获取布尔返回值,python,oracle11g,oracle12c,cx-oracle,Python,Oracle11g,Oracle12c,Cx Oracle,我整天都在努力工作,试图使用cx_Oracle从PL/SQL函数中获取布尔值。我看到过一些帖子谈论使用其他数据类型(如char或integer)来存储返回值,但是当我尝试使用这些解决方案时,我得到了一个不正确的数据类型错误。首先,让我展示代码 def lives_on_campus(self): cursor = conn.cursor() ret = cursor.callfunc('students_api.lives_on_campus', bool, [self.pidm])

我整天都在努力工作,试图使用cx_Oracle从PL/SQL函数中获取布尔值。我看到过一些帖子谈论使用其他数据类型(如char或integer)来存储返回值,但是当我尝试使用这些解决方案时,我得到了一个不正确的数据类型错误。首先,让我展示代码

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
文件“student extracts.py”,第134行,在
如果学生住在校园():
“student extracts.py”文件,第58行,校园生活
ret=cursor.callfunc('students\u api.lives\u on\u campus',bool[self.pidm])
cx_Oracle.DatabaseError:DPI-1050:Oracle客户端库的版本为11.2,但需要12.1或更高版本
如果使用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
回溯(最近一次呼叫最后一次):
文件“student extracts.py”,第134行,在
如果学生住在校园():
“student extracts.py”文件,第58行,校园生活
ret=cursor.callfunc('students\u api.lives\u on\u campus',bool[self.pidm])
cx_Oracle.DatabaseError:ORA-03115:不支持的网络数据类型或表示形式
基本上,无论我使用哪个版本的SQL客户机,它都会出错。现在,我知道如果数据库版本是12cr2,上面的代码就可以工作了。不幸的是,我们的测试环境中只有这个版本,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())

谢谢克里斯托弗,我想实现我想要的唯一方法就是完全避免布尔人。这有点让人扫兴。我找到了一种让你的代码短一点的方法。我希望你不介意编辑。另一种方法是升级!