douza6300 2015-03-07 09:51 采纳率: 0%
浏览 891

oci_execute():ORA-01840:日期格式的输入值不够长

I am currently receiving the following error message from oci in php (I've been on it for a few hours).

oci_execute(): ORA-01840: input value not long enough for date format

It strange, because when I run the query within SQL Developer it seems to work fine.

This makes me think that when I bind the parameter it is turning the dates into a type that is not able to calculate using conventional operators in oracle.

$startDateTime = '2015-03-06 00:00:00';
$endDateTime = '2015-04-06 00:00:00';
$value = '20';
$type = '$';

$SQL = "SELECT count(*) AS \"COUNT\"
               FROM bonus where value = :d_value
               AND TYPE = :d_type
               AND ((:d_valid_from between valid_from AND valid_till) OR (:d_value_till between valid_from AND valid_till) OR (:d_valid_from < valid_from AND valid_till < :d_valid_till))";

 $this->stmnt = $this->conn->prepare($SQL);
 $this->stmnt->bindParam('d_valid_from', $startDateTime);
 $this->stmnt->bindParam('d_valid_till', $endDateTime);
 $this->stmnt->bindParam('d_value', $value);
 $this->stmnt->bindParam('d_type', $type);
 $this->stmnt->execute();

I am unable to find many resources that deal with php directly with this problem in hand. Does anybody have any experience with it?

  • 写回答

1条回答 默认 最新

  • douou9786 2015-03-07 17:17
    关注

    I think that your dates are being bound as strings in the query. Assuming that the columns you are comparing it to (e.g. valid_from) are dates, then the string value is being converted to a date using the default date format for the sessions. The difference in behavior in SQL Developer is probably because the default format is different.

    Anyway, the solution is to follow a very simple and important rule, which is not to rely on default type conversion. Explicitly convert the string to a date in your query, specifying the appropriate format:

    TO_DATE( :d_valid_from, 'YYYY-MM-DD HH24:MI:SS' )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑