我想判断 当前时间 是不是在 某个时间段内
表结构
。start_time end_time语句select * from FCFJ_WSKS_SJ where to_date('2011-4-2','yyyy-mm-dd hh24:mi:ss')
between to_date('2011-4-1 14:55:50','yyyy-mm-dd hh24:mi:ss') and to_date('2011-4-30 14:45:56','yyyy-mm-dd hh24:mi:ss')
这样是对的 为什么 我把 起始时间 '2011-4-1 14:55:50' 换成 start_time,结束时间 '2011-4-30 14:45:56' 换成end_time就不对了呢??
表结构
。start_time end_time语句select * from FCFJ_WSKS_SJ where to_date('2011-4-2','yyyy-mm-dd hh24:mi:ss')
between to_date('2011-4-1 14:55:50','yyyy-mm-dd hh24:mi:ss') and to_date('2011-4-30 14:45:56','yyyy-mm-dd hh24:mi:ss')
这样是对的 为什么 我把 起始时间 '2011-4-1 14:55:50' 换成 start_time,结束时间 '2011-4-30 14:45:56' 换成end_time就不对了呢??
between to_date('2011-4-1 14:55:50','yyyy-mm-dd hh24:mi:ss') and to_date('2011-4-30 14:45:56','yyyy-mm-dd hh24:mi:ss')
这样是对的 为什么 我把 起始时间 '2011-4-1 14:55:50' 换成 start_time,结束时间 '2011-4-30 14:45:56' 换成end_time就不对了呢??
检查数据类型,你这个是什么业务逻辑,正常的来说,条件左边的,,不要用函数给他来转
between to_char(start_time,'yyyy-mm-dd hh24:mi:ss') and to_char('2011-4-30 14:45:56','yyyy-mm-dd hh24:mi:ss')
直接搞定!
如果是日期型
select *
from FCFJ_WSKS_SJ where to_date('2011-4-2','yyyy-mm-dd hh24:mi:ss')
between start_time and end_time
如果是字符串型
select * from FCFJ_WSKS_SJ where to_date('2011-4-2','yyyy-mm-dd hh24:mi:ss')
between to_date(start_time,'yyyy-mm-dd hh24:mi:ss') and to_date(end_time,'yyyy-mm-dd hh24:mi:ss')