select * from community t where to_date(t.create_time,'yyyy-mm-dd')> '2008-3-12' to_date之后又与字符做比较?日期与字符型比较?select * from community t where to_char(t.create_time,'yyyy-mm-dd')> '2008-3-12' 这样才正确!
create_time字段是日期型 日期型的不需要to_date select * from community t where t.create_time>to_date( '2008-3-12' ,'yyyy-mm-dd')
select * from community t where t.create_time> to_date('2008-03-12','YYYY-MM-DD'); 注意大小写和补0
1楼查不到数据. 2楼可以查到,为什么 select * from community t where t.create_time> to_date( '2008-03-14' ,'yyyy-mm-dd') 查出来的结果里面还包括2008-03-14的? 2008-3-14 9:07:29 2008-3-17 18:18:08 2008-3-14 9:24:08 2008-3-14 9:26:29 2008-3-14 10:11:47 看到了吗?
select * from community t where t.create_time>= to_date('2008-03-15 00:00:00 ','YYYY-MM-DD HH24:MI:SS');
这样才正确!
日期型的不需要to_date
select * from community t where t.create_time>to_date( '2008-3-12' ,'yyyy-mm-dd')
注意大小写和补0
2楼可以查到,为什么
select * from community t where t.create_time> to_date( '2008-03-14' ,'yyyy-mm-dd')
查出来的结果里面还包括2008-03-14的?
2008-3-14 9:07:29
2008-3-17 18:18:08
2008-3-14 9:24:08
2008-3-14 9:26:29
2008-3-14 10:11:47
看到了吗?
这个表示的是 2008-03-14 00:00:00
所有14号的都比这个日期大
一楼的做法是把时间转化成字符,那么这样比起来就是比字符大小.
二楼的做法是把字符转化成时间,那么这样比起来就是比时间了.举一个非常简单的例子
String型的 11 是小于 9的.
而int型的 11 是大于 9的.这样写不知道你能明白不.