• oracle sql查询日期


    查询今日每一分钟

    SELECT CONCAT(TO_CHAR(Trunc(SYSDATE)+(ROWNUM-1)/24, 'YYYY-MM-DD HH24'),':00:00') timeM 
         FROM DUAL CONNECT BY ROWNUM <= 24

    查询结果:

    2020-11-10 00:00:00  2020-11-10 01:00:00  2020-11-10 02:00:00  2020-11-10 03:00:00
    2020-11-10 04:00:00  2020-11-10 05:00:00  2020-11-10 06:00:00  2020-11-10 07:00:00
    2020-11-10 08:00:00  2020-11-10 09:00:00  2020-11-10 10:00:00  2020-11-10 11:00:00
    2020-11-10 12:00:00  2020-11-10 13:00:00  2020-11-10 14:00:00  2020-11-10 15:00:00
    2020-11-10 16:00:00  2020-11-10 17:00:00  2020-11-10 18:00:00  2020-11-10 19:00:00
    2020-11-10 20:00:00  2020-11-10 21:00:00  2020-11-10 22:00:00  2020-11-10 23:00:00

    查询本周每一天

     SELECT to_char(TRUNC(NEXT_DAY(SYSDATE-8,1)+ROWNUM),'YYYY-MM-DD') timeM
        FROM DUAL CONNECT BY ROWNUM <= TO_NUMBER(TRUNC(sysdate)- TO_DATE(TRUNC(NEXT_DAY(SYSDATE-8,1)+0)))

    -- 查询结果
    2020-11-09  2020-11-10  2020-11-11  

    查询本月每一天

    SELECT TO_CHAR(TRUNC(SYSDATE, 'MM') + ROWNUM - 1, 'YYYY-MM-DD') timeM
         FROM DUAL
         CONNECT BY ROWNUM <= TO_NUMBER(TO_CHAR(LAST_DAY(SYSDATE), 'dd'))
    -- 查询结果
    2020-11-01  2020-11-02  2020-11-03  2020-11-04  2020-11-05
    2020-11-06  2020-11-07  2020-11-08  2020-11-09  2020-11-10
    2020-11-11  2020-11-12  2020-11-13  2020-11-14  2020-11-15
    2020-11-16  2020-11-17  2020-11-18  2020-11-19  2020-11-20
    2020-11-21  2020-11-22  2020-11-23  2020-11-24  2020-11-25
    2020-11-26  2020-11-27  2020-11-28  2020-11-29  2020-11-30

    查询最近一年

    SELECT TO_CHAR( ADD_MONTHS( SYSDATE, - ROWNUM + 1 ), 'yyyy-mm' ) month FROM DUAL CONNECT BY ROWNUM <= 13

    查询结果:

    2020-11  2020-10  2020-09  2020-08  2020-07
    2020-06  2020-05  2020-04  2020-03  2020-02
    2020-01  2019-12  2019-11

  • 相关阅读:
    成长——新的开始,一切都是美好的
    asp.net mvc项目自定义区域
    随便记录下系列
    插件化编程实现的一份糖炒栗子~~
    个人项目框架搭建 -- 缓存接口与实现
    个人项目框架搭建 -- 仓储模式使用
    个人项目框架搭建 -- Autofac简单使用记录
    至自己
    使用T4模板合并js文件
    HTML5学习笔记
  • 原文地址:https://www.cnblogs.com/snailgirl/p/13954078.html
Copyright © 2020-2023  润新知