sql语句 以时间为条件检索的语句问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 11:22:30
使用的PL/SQL DEVELOPER 检索语句如下:
select * from prescript_sum where cashtime < to_date('2008-04-11','yyyy-mm-dd'); ----------执行成功
select * from prescript_sum where cashtime < to_date('2008-04-11 00:00:00','yyyy-mm-dd hh:mm:ss');---------- 执行失败 提示错误是格式代码出现两次
我想要将检索实践精确到秒 那么这条语句应该如何修改 THS!

改成下面的就可以了。

select * from prescript_sum where cashtime < to_date('2008-04-11 00:00:00','yyyy-mm-dd hh24:mi:ss');

原因:SQL中不区分大小写,且格式里不可出现相同的两个 mm,MM和mm被认为是相同的格式代码,所以Oracle的SQL采用了mi代替分钟

select * from prescript_sum where cashtime < to_date('2008-04-11 00:00:00','yyyy-mm-dd hh:mi:ss');
yyyy-mm-dd 年-月-日
hh:mi:ss 时:分:秒
mm与mi区别是:月 秒

实在没看出来shaoshuai_bd的回答有什么意义?

select * from prescript_sum where cashtime < to_date('2008-04-11 00:00:00','yyyy-mm-dd hh:MM:ss');

提示错误是因为 你月份 和分钟那里用的是同样的“格式代码”

时间分钟那里 应该是大写M 小写是月 若错了 那你就反过来试试(月MM 分mm)~~~ 不太记得了