oracle按时间查询
1.按月查询时,下面这条语句可以获取下个月1号
select ?add_months( to_date('2006-12-1','yyyy-MM-dd'), 1) ?from dual ?;
2.下面语句可以查询2006年12月数据
select * from wf_wfinfo t where t.wfstarttime between to_date('2006-12-1','yyyy-MM-dd')
and (select ?add_months( to_date('2006-12-1','yyyy-MM-dd'), 1) ?from dual);
也可以简写成:
select * from wf_wfinfo t where t.wfstarttime between to_date('2006-12-1','yyyy-MM-dd')
and ( add_months( to_date('2006-12-1','yyyy-MM-dd'), 1) );
3.一般查询12月数据
SELECT T.*,T.ROWID FROMTABLE t WHERE t.starttime BETWEEN? to_date('2011-12-01','yyyy-MM-dd') AND to_date('2011-12-31','yyyy-MM-dd' )?
4.下面数据库中时间为字符串查询的一种方式
?select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual
5.数据库中为字符串情况,前台转换数据也为字符串情况:
select to_date(t.operatime,'yyyy-mm-dd hh24:mi:ss') from inck_t_adsl_devnbr_ne_log t
where to_date(t.operatime,'yyyy-mm-dd hh24:mi:ss')>=to_date('2010-03-10 00:00:00','yyyy-mm-dd hh24:mi:ss') and
?to_date(t.operatime,'yyyy-mm-dd hh24:mi:ss')<=to_date('2011-03-10 00:00:00','yyyy-mm-dd hh24:mi:ss');
?
select to_date(t.operatime,'yyyy-mm-dd hh24:mi:ss') from inck_t_adsl_devnbr_ne_log t
where to_date(t.operatime,'yyyy-mm-dd hh24:mi:ss') between to_date('2010-03-10 00:00:00','yyyy-mm-dd hh24:mi:ss') and
?to_date('2011-03-10 00:00:00','yyyy-mm-dd hh24:mi:ss');
select to_date('2004-05-07 13:23:44','yyyy-mm-dd hh24:mi:ss') ? ?from dual