Get the App
SLTechnology News&Howtos  ›  Database  › 

How to query the month list / date list crossed by two dates by Oracle

Shulou Source: shulou.com Published: 2022-05-31 20:06:28 11月16日 Update

Editor to share with you how Oracle query 2 dates across the month list / date list, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Basic logic formula:

Select Rownum, start date + Rownum-1 from dual connect by rownum < end date-start date + 2

two。 Query the yyyy-mm-dd list of dates crossed by 2 dates:

Query results:

SQL code (start time: 2019-01-22, end time: 2019-01-02):

Select Rownum, to_date ('2019-01-02,' yyyy-mm-dd') + Rownum-1from dualconnect by rownum < to_date ('2019-01-22,' yyyy-mm-dd')-to_date ('2019-01-02,' yyyy-mm-dd') + 2

3. Query the yyyy-mm list of months spanned by 2 dates:

Query results:

SQL code (start time: 2020-03-15, end time: 2019-01-02):

Select ss.DAY_ID from (SELECT TO_CHAR (TO_DATE ('2019-01-02)) + ROWNUM-1,' YYYY-MM') DAY_IDfrom dualconnect by rownum < to_date ('2020-03-15,' yyyy-mm-dd')-to_date ('2019-01-02' 'yyyy-mm-dd') + 2) ss GROUP BY DAY_ID ORDER BY DAY_ID and above are all the contents of the article "how to query the month list / date list crossed by 2 dates by Oracle" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Date query time month article code content result not much formula most more knowledge industry information information channel logic channel reference learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL Xiaomi Microsoft Shulou Tech Info