时间:2021-07-01 10:21:17 帮助过:82人阅读
ORACLE任意时间段内所有天数查询,没必要借助什么all_objects 无 /* 查询2013-11-25至2014-12-28内所有日期天数 */select date '2013-11-25' + (rownum - 1) dt from dual connect by rownum = (date '2014-12-28' - date '2013-11-25' + 1) /* 查询2013-11-25
ORACLE任意时间段内所有天数查询,没必要借助什么all_objects/* 查询2013-11-25至2014-12-28内所有日期天数 */ select date '2013-11-25' + (rownum - 1) dt from dual connect by rownum <= (date '2014-12-28' - date '2013-11-25' + 1)
/* 查询2013-11-25至2014-12-28包含的月份,以及每月包含的天数 */ select to_char(dt,'yyyy-mm'), count(to_char(dt,'yyyy-mm')) days, mm from( select date'2013-11-25' + (rownum - 1) dt, to_char(last_day(date'2013-11-25' + (rownum - 1)),'mm') mm from dual connect by rownum <= (date'2014-12-28' - date'2013-11-25' + 1) ) group by to_char(dt,'yyyy-mm'),mm order by to_char(dt,'yyyy-mm')