与cx_oracle

时间:2019-07-26 23:22:01

标签: python cx-oracle

当尝试处理函数并绑定一些参数时,即时通讯会不断产生奇怪的结果

我试图在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
``

1 个答案:

答案 0 :(得分:0)

    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

最后由我自己找到了一个解决方案),希望对下一代有用。