简体   繁体   English

在Oracle控制台中可以使用相同的SQL,而在php中则不能

[英]Same SQL in Oracle console works and in php not

I have a problem with this sql: 我对这个sql有问题:

select DATE_FIELD from table where
DATE_FIELD >= to_date(to_char(sysdate, 'yyyy/mm/dd'), 'yyyy/mm/dd')
and
DATE_FIELD <= to_date(to_char(sysdate, 'yyyy/mm/dd')+1, 'yyyy/mm/dd')

I would like to get the date from today 00:00:00 to tomorrow 00:00:00. 我想获取从今天00:00:00到明天00:00:00的日期。

The DATE_FIELD field's DATA TYPE is DATE DATE_FIELD字段的数据类型为DATE

In Tora/Toad works and in php not. 在Tora / Toad中工作,而在php中不行。

Error code: 错误代码:

PHP Warning:  oci_execute(): ORA-01722: invalid number

Your query: 您的查询:

select DATE_FIELD
from table
where DATE_FIELD >= to_date(to_char(sysdate, 'yyyy/mm/dd'), 'yyyy/mm/dd') and
      DATE_FIELD <= to_date(to_char(sysdate, 'yyyy/mm/dd')+1, 'yyyy/mm/dd')
----------------------------------------------------------^

I don't know what this would work anywhere, because to_char( . . . ) + 1 should fail. 我不知道这在哪里都行得通,因为to_char( . . . ) + 1应该会失败。 Well, I could imagine an arcane setting that would recognize the 'yyyy/mm/dd' date format and convert the string back to a date to add 1. 好吧,我可以想象一个神秘的设置,该设置可以识别'yyyy/mm/dd'日期格式,并将字符串转换回添加1的日期。

I would suggest the much simpler: 我建议简单得多:

where DATE_FIELD >= trunc(sysdate) and DATE_FIELD < trunc(sysdate + 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM