dongqiao6445 2016-06-23 13:19
浏览 55

ORACLE存储过程适用于sql开发人员,但不适用于php

I'm confronted to a strange issue here, I try to use an oracle stored procedure which works fine on sqldeveloper and java, but not on php.

I'm executing the query this way :

//$rqt_date = "SELECT DECODE( 1, NULL, 1, 33, '1', 44 ) as test FROM DUAL";
$rqt_date = "SELECT DATEPARAM('23/06/2016') as date_1900 FROM DUAL";

$parsed = ociparse($db_link, $rqt_date);
oci_execute($parsed,OCI_NO_AUTO_COMMIT);
while (($row = oci_fetch_array($parsed, OCI_BOTH)) != false)
{
    print_r($row);
}

I test using the commented $rqt_date (decode) : I get results

Array
(
    [0] => 44
    [TEST] => 44
)

But when I use DATEPARAM I get 0 as values instead of 42542 (number of days since 1900) :

Array
(
    [0] => 0
    [DATE_1900] => 0
)

What I get in sqldeveloper:

http://i.stack.imgur.com/6b40V.png

I have no errors in the php logs.

The info about my server : PHP Version 5.3.8 System Windows NT BOWSER 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586

  • 写回答

2条回答 默认 最新

  • doushi1510 2016-06-23 14:16
    关注

    But when I use DATEPARAM I get [...] number of days since 1900

    The DATEPARAM function should be very simple:

    CREATE FUNCTION dateparam (
      dt IN DATE
    ) RETURN INTEGER DETERMINISTIC
    IS
    BEGIN
      RETURN dt - DATE '1900-01-01';
    END;
    /
    

    Now, this takes a DATE datatype (not a string).

    So in PHP (not my language, so please excuse any errors) you can pass the required value as a bind variable:

    $rqt_date = "BEGIN :r := DATEPARAM( :dt ); END;";
    $parsed = ociparse($db_link, $rqt_date);
    oci_bind_by_name($parsed, ":dt", new DateTime( "2016-06-23" ) );
    oci_bind_by_name($parsed, ":r", $r, 40 );
    oci_execute($parsed,OCI_NO_AUTO_COMMIT);
    print "$r
    ";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?