Home > Database > Mysql Tutorial > ORACLE任意时间段内所有天数日期查询

ORACLE任意时间段内所有天数日期查询

WBOY
Release: 2016-06-07 14:57:42
Original
1524 people have browsed it

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)




Copy after login
/* 查询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')
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template