select * from time where
to_date(tTime,'yyyy-MM-dd HH24mi') >='1031' and to_date(tTime,'yyyy-MM-dd HH24mi') <='1940'
时间列是20120223200404这样的现在我需要根据客户输入的时间点 比如201203221022 到 201203221055 这段时间内的记录 为什么错了啊
to_date(tTime,'yyyy-MM-dd HH24mi') >='1031' and to_date(tTime,'yyyy-MM-dd HH24mi') <='1940'
时间列是20120223200404这样的现在我需要根据客户输入的时间点 比如201203221022 到 201203221055 这段时间内的记录 为什么错了啊
看你的数据,时间列是char型的,那就不用to_date了:
select * from time where substr(tTime,1,4) >='1031' and substr(tTime,1,4) <='1940';
首先你这SQL犯了两个错误1、to_date(tTime,'yyyy-MM-dd HH24mi') 错误
正确应该是 to_date(tTime,'yyyy-mm-dd hh24:mi')2、to_date(tTime,'yyyy-MM-dd HH24mi') >='1031' 这个等式错误
左边TO_DATE 出来的是日期格式 而右边是 字符串格式,肯定会报错
正确写法:
select * from time
where to_date(tTime,'yyyy-mm-dd hh24:mi') >= to_date('201203221022','yyyy-mm-dd hh24:mi')
and to_date(tTime,'yyyy-MM-dd HH24:mi') <= to_date('201203221055','yyyy-mm-dd hh24:mi')
不管要选取那个时间段,最好能都包括进去 You may as well like this:
select * from time
where substr(tTime,1,14)>='201203221022' and substr(tTime,1,14)<='201203221055' ;
ERROR: ORA-01861: literal does not match format string