我有这样一个问题:我有一个表,其中的列是一篇文章,日期从和日期到(这是一个时间间隔),例如:
ITEM | DATE_FROM | DATE_TO
IT_01 | 01/01/2021 | 07/01/2021
我想生成一个查询,生成一个新列,其中指定了从日期到日期的间隔,生成具有该间隔的文章的行,留下如下结果:
ITEM | DATE_FROM | DATE_TO | DATE_PER_DAY
--------+---------------+-----------------+------------------
IT_01 | 01/01/2021 | 07/01/2021 | *01/01/2021*
IT_01 | 01/01/2021 | 07/01/2021 | *02/01/2021*
IT_01 | 01/01/2021 | 07/01/2021 | *03/01/2021*
IT_01 | 01/01/2021 | 07/01/2021 | *04/01/2021*
IT_01 | 01/01/2021 | 07/01/2021 | *05/01/2021*
IT_01 | 01/01/2021 | 07/01/2021 | *06/01/2021*
IT_01 | 01/01/2021 | 07/01/2021 | *07/01/2021*
感谢这是您需要的行生成器:
SQL> with test (item, date_from, date_to) as
2 (select 'IT_01', date '2021-01-01', date '2021-01-07' from dual)
3 select item, date_from, date_to, date_from + level - 1 as date_per_day
4 from test
5 connect by level <= date_to - date_from + 1
6 order by date_per_day;
ITEM DATE_FROM DATE_TO DATE_PER_D
----- ---------- ---------- ----------
IT_01 01.01.2021 07.01.2021 01.01.2021
IT_01 01.01.2021 07.01.2021 02.01.2021
IT_01 01.01.2021 07.01.2021 03.01.2021
IT_01 01.01.2021 07.01.2021 04.01.2021
IT_01 01.01.2021 07.01.2021 05.01.2021
IT_01 01.01.2021 07.01.2021 06.01.2021
IT_01 01.01.2021 07.01.2021 07.01.2021
7 rows selected.
SQL>