V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
qile1
V2EX  ›  Python

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

  •  
  •   qile1 · 2020-03-03 02:48:46 +08:00 · 1980 次点击
    这是一个创建于 1507 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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)
    
    1 条回复    2020-03-03 09:07:20 +08:00
    renmu
        1
    renmu  
       2020-03-03 09:07:20 +08:00 via Android
    a,b,c=function(),或者 a=function(),这样 a 的话是一个元组
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5277 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:51 · PVG 15:51 · LAX 00:51 · JFK 03:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.