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 Python 连接 oracle 执行后台包如何实现请教

  •  
  •   qile1 · 2022-12-18 22:46:57 +08:00 · 2531 次点击
    这是一个创建于 485 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题,后端发来一段代码,我看也没什么问题,但是执行时候偶尔会执行失败,提示找不到订单号,用 plsql 执行就可以获取数据,20 条可能有一条会执行失败,大家有没有更好的建议或者方法 代码如下

    try:
        cursor = connection.cursor()
        ad_startdate = datetime.now() - timedelta(days=10)
        ad_enddate = datetime.now()
        mycs = cursor.var(cx_Oracle.CURSOR)
        result = cursor.var(cx_Oracle.NUMBER)
        k = cursor.execute("""begin
          :result := pk_app.uf_get_order_List(as_ic_card => :as_ic_card,
                                                  ad_startdate => :ad_startdate,
                                                  ad_enddate => :ad_enddate,
                                                  mycs => :mycs);
        end;
            """, as_ic_card=as_ic_card, ad_startdate=ad_startdate, ad_enddate=ad_enddate, mycs=mycs,
                           result=result)
        print("----------")
        print(k)
        print("refCursor = mycs.getvalue()")
        refCursor = mycs.getvalue()
        data_list = []
        for row in refCursor:
            print(row)
            data_list.append(row[:])
        cursor.close()
        print (data_list)
    except Exception as e:
        print(e)
        try:
            cursor.close()
        except Exception as e1:
            print(e1)
    
        上面是代码样例,查询最近 10 天订单
    
    3 条回复    2022-12-30 22:46:46 +08:00
    qile11
        1
    qile11  
       2022-12-19 13:50:08 +08:00 via Android
    有没有哪位遇到过,谢谢
    qile11
        2
    qile11  
       2022-12-20 15:06:38 +08:00 via Android
    主题页看不到帖子啦,是不是已经沉啦
    qile11
        3
    qile11  
       2022-12-30 22:46:46 +08:00 via Android
    直接 exec 执行,返回类型可能需要处理下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1129 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 22:59 · PVG 06:59 · LAX 15:59 · JFK 18:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.