【问题标题】:ORA-01036 error, when binding variables with cx_oracle使用 cx_oracle 绑定变量时出现 ORA-01036 错误
【发布时间】:2019-07-26 23:22:01
【问题描述】:

当试图处理一个函数并绑定一些参数时,我总是得到奇怪的结果

我尝试在 vars 中使用不同的变量名和不同的数字,但没有成功

        res_sum = -1
        good_id = 430815501
        self.cur.prepare(":smth := AP_USER_OFFICE_PKG_S.GET_SERVS_SUMS(:smth2).N_GOOD_SUM;")

        self.cur.execute(None, {'smth': res_sum, 'smth2': good_id})

我期待函数返回结果,但得到的只是


    self.cur.execute(None, {'smth': res_sum, 'smth2': good_id})
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
``

【问题讨论】:

    标签: python cx-oracle


    【解决方案1】:
        def get_service_sum(self, good_id):
            SQL_BLOCK = '''
            DECLARE
                v_good_id    NUMBER;
                v_result  NUMBER;
            BEGIN
                v_good_id := :i_good_id;
                v_result := AP_USER_OFFICE_PKG_S.GET_SERVS_SUMS(v_good_id).N_GOOD_SUM;
                :o_result := v_result;  -- (1)
            END;
    
            '''
            res_sum = self.cur.var(cx_Oracle.NUMBER)
            good_id = 430815501
    
            self.cur.execute(SQL_BLOCK, i_good_id=good_id, o_result=res_sum)
            res = res_sum.getvalue()  # (4)
            return res
    

    终于自己找到了解决办法)希望对下一代有用)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      相关资源
      最近更新 更多