Oracle查询一段日期内的星期的日期..例如我要查2011-3-18至2011-3-30内所有星期一的日期..应该怎样查询

如题所述

select tdate, to_char(tdate,'day')
from (
select to_date('2011-03-18','yyyy-mm-dd') + rownum -1 as tdate
from all_objects
where rownum <= to_date('2011-03-30','yyyy-mm-dd') - to_date('2011-03-18','yyyy-mm-dd') + 1
) t
where to_char(tdate,'day') = '星期一'
其中t表是构建你需要的这一个时间段的日期列表, to_char(days,'day')得到的结果是星期几
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-30
SQL: select to_char(时间,'d'),时间 from table_name where to_char(时间,'d') not in ('2','3','4','5','6')
and 时间 between 2011-3-18 and 2011-3-30
解释
----not in ('2','3','4','5','6')中,1--周日,2--周一,3--周二,4--周三。。。7--周六
第2个回答  2011-03-30
select * from userinfo p where P.IDATE BETWEEN TO_DATE('2011-03-18','YYYY-MM-DD HH24')
AND TO_DATE('2011-03-30','YYYY-MM-DD HH24')
相似回答