V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Dec 18, 2022 · 3602 views
    This topic created in 1227 days ago, the information mentioned may be changed or developed.

    如题,后端发来一段代码,我看也没什么问题,但是执行时候偶尔会执行失败,提示找不到订单号,用 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 replies    2022-12-30 22:46:46 +08:00
    qile11
        1
    qile11  
       Dec 19, 2022 via Android
    有没有哪位遇到过,谢谢
    qile11
        2
    qile11  
       Dec 20, 2022 via Android
    主题页看不到帖子啦,是不是已经沉啦
    qile11
        3
    qile11  
       Dec 30, 2022 via Android
    直接 exec 执行,返回类型可能需要处理下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5360 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 03:49 · PVG 11:49 · LAX 20:49 · JFK 23:49
    ♥ Do have faith in what you're doing.