将日期参数绑定到存储过程


Binding date parameters to stored procedure

我正在尝试将日期参数绑定到存储过程。$conn可以,所有参数都正确。我在数据库中直接调用这个过程没有问题。我试着打印错误,但是什么也没得到。我现在没有附加exec_cur,因为我猜,问题是在绑定或调用过程。我还尝试引用i_start和i_end:

 TO_DATE(':i_start', 'DD.MM.YYYY'), TO_DATE( ':i_end', 'DD.MM.YYYY')

在我看来,调用没有得到结果。我得到空光标,而从代码调用它。当直接调用它时,我得到了许多条目。

函数:

function &HST($conn, $i_qot_id, $i_startend, $i_order_by, $i_max_rows, $v_cache_filename)
{
        $outrefc = oci_new_cursor($conn);
         $oerr = OCIError( $outrefc);
         echo "Fetch Code 1:".$oerr["message"];
        $mycursor = oci_parse($conn, "begin PPCKG.HST (:i_qot_id, TO_DATE(:i_start, 'DD.MM.YYYY'), TO_DATE( :i_end, 'DD.MM.YYYY') , :i_order_by, :i_max_rows, :curs); end");
        print $i_startend[0].$i_startend[1].$i_qot_id. $i_order_by. $i_max_rows;
        $oerr = OCIError( $mycursor);
        echo "Fetch Code 1:".$oerr["message"];
        oci_bind_by_name($mycursor, ':i_qot_id'  , $i_qot_id);
        oci_bind_by_name($mycursor, ':i_start'   , $i_startend[0]);
        oci_bind_by_name($mycursor, ':i_end'     , $i_startend[1]);
        oci_bind_by_name($mycursor, ':i_order_by', $i_order_by);
        oci_bind_by_name($mycursor, ':i_max_rows', $i_max_rows);
        oci_bind_by_name($mycursor, ':curs'      , $outrefc, -1, OCI_B_CURSOR);
        $oerr = OCIError( $mycursor);
        echo "Fetch Code 1:".$oerr["message"];
        return exec_cur( $mycursor, $outrefc, $v_cache_filename);
}

为什么在调用存储过程时要将字符串值转换为日期?为什么不把它转换成日期之前呢?

  • 首先你必须将字符串转换为日期
<>之前$time = strtotime(:i_start);$newformat = date('Y-m-d',$time);之前
  • 然后将此值传递给oracle存储过程
<>之前$mycursor = oci_parse($conn, "开始PPCKG。HST (:i_qot_id,:newformat,…);最后,");之前