[Oracle SQL Tricks] Generating Dates Between Two Dates


Posted by Vanchy on 2021-02-02

1. Goal

用一段SQL產生指定日期區間內的所有日期

2. Code

SELECT backup_date
FROM ( SELECT trunc(to_date('20210201', 'yyyymmdd') - rownum - 1) as backup_date
       FROM dual
       CONNECT BY rownum <= 5
     )

3.Result

backup_date
2021/02/01
2021/01/31
2021/01/30
2021/01/29
2021/01/28

4. Description

  • to_date(‘20210201’, ‘yyyymmdd’):可換成任何日期
  • rownum <= 5:可調整產生幾筆日期資料

5. Reference

Generate a range of dates using SQL


#Oracle SQL







Related Posts

從頭打造一個簡單的 Virtual DOM

從頭打造一個簡單的 Virtual DOM

[重新理解C++] Package 觀念: ABI 和 API

[重新理解C++] Package 觀念: ABI 和 API

[第三週] NPM簡介

[第三週] NPM簡介


Comments