cx_Oracle 在执行包文件 function 时有多个出参该如何获取

2020-03-03 02:48:46 +08:00
 qile1

oracle 数据库 包文件这样创建的

function pf_get_info(id        in varchar2,
                     name      out varchar2,
                     sex       out varchar2,
                     birthdate out date,
                     cd_no     out varchar2) return integer is

  e_info_no_found exception;
begin
  begin
    select name,
           decode(sex, '0', '男', '1', '女', '未知'),
           birthdate,
           nvl(cpr_no, '')
      into rs_name, rs_sex, rdt_birthdate, rs_cd_no
      from basic_info
     where id = id;
  exception
    when NO_DATA_FOUND then
      raise e_info_no_found;
  end;

  return 0;
  --异常处理
exception
  when e_info_no_found then
    return - 1;
  
end pf_get_info;

python 使用 cx_Oracle.Cursor.callfunc(proc, returnType, [params]) 调用函数 ,out 为多种类型的多个参数该如何获取呢?我看网上都是返回一个值的函数调用,我的样例代码如下

import cx_Oracle

class HR:
    def __enter__(self):
        self.__db = cx_Oracle.Connection("user/123@//127.0.0.1:1521/ydyf")
        self.__cursor = self.__db.cursor()
        return self

    def __exit__(self, type, value, traceback):
        self.__cursor.close()
        self.__db.close()

    def pf_get_info(self,id):

        l_rs_name = self.__cursor.var(cx_Oracle.STRING)
        l_rs_sex = self.__cursor.var(cx_Oracle.STRING)
        l_rdt_birthdate = self.__cursor.var(cx_Oracle.DATETIME)
        l_rs_cd_no = self.__cursor.var(cx_Oracle.STRING)
        # as_sick_id = self.__cursor.var(cx_Oracle.STRING)
        self.__cursor.callfunc("PKG_HR.pf_get_info",cx_Oracle.NUMBER,[id])

        return l_rs_name,l_rs_sex,l_rdt_birthdate,l_rs_cd_no

ggg=HR
id="2094"
l_rs_name,l_rs_sex,l_rdt_birthdate,l_rs_cd_no=ggg.pf_get_info(id)
1991 次点击
所在节点    Python
1 条回复
renmu
2020-03-03 09:07:20 +08:00
a,b,c=function(),或者 a=function(),这样 a 的话是一个元组

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/649278

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX