zkuste toto,
ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD HH AM';
SELECT to_date('12/31/2017', 'MM/DD/YYYY') + (FLOOR(rownum/24) + (MOD(rownum-1, 24)/24)) dt
FROM DUAL
CONNECT BY rownum <= ((to_date('01/02/2018', 'MM/DD/YYYY')+(1/23)) - to_date('12/31/2017', 'MM/DD/YYYY') + (MOD(rownum, 24)/24)) * 24
ORDER BY 1;
Výstup:
DT
-----------
12/31 12 AM
12/31 01 AM
12/31 02 AM
12/31 03 AM
12/31 04 AM
12/31 05 AM
12/31 06 AM
12/31 07 AM
12/31 08 AM
12/31 09 AM
12/31 10 AM
12/31 11 AM
12/31 12 PM
12/31 01 PM
12/31 02 PM
12/31 03 PM
12/31 04 PM
12/31 05 PM
12/31 06 PM
12/31 07 PM
12/31 08 PM
12/31 09 PM
12/31 10 PM
01/01 12 AM
01/01 01 AM
01/01 02 AM
01/01 03 AM
01/01 04 AM
01/01 05 AM
01/01 06 AM
01/01 07 AM
01/01 08 AM
01/01 09 AM
01/01 10 AM
01/01 11 AM
01/01 12 PM
01/01 01 PM
01/01 02 PM
01/01 03 PM
01/01 04 PM
01/01 05 PM
01/01 06 PM
01/01 07 PM
01/01 08 PM
01/01 09 PM
01/01 10 PM
01/01 11 PM
01/02 12 AM
01/02 01 AM
01/02 02 AM
01/02 03 AM
01/02 04 AM
01/02 05 AM
01/02 06 AM
01/02 07 AM
01/02 08 AM
01/02 09 AM
01/02 10 AM
01/02 11 AM
01/02 12 PM
01/02 01 PM
01/02 02 PM
01/02 03 PM
01/02 04 PM
01/02 05 PM
01/02 06 PM
01/02 07 PM
01/02 08 PM
01/02 09 PM
01/02 10 PM
01/02 11 PM
Vybráno 71 řádků
Pokud chcete zadat počáteční a koncovou hodinu, použijte dotaz níže, právě jsem upravil klauzuli CONNECT BY a ORDER BY svého prvního dotazu.
SELECT to_date('12/31/2017 10:00 PM', 'MM/DD/YYYY HH:MI AM') + (FLOOR(rownum/24) + (MOD(rownum-1, 24)/24)) dt
FROM DUAL
CONNECT BY rownum <= CEIL(((to_date('01/01/2018 02:00 AM', 'MM/DD/YYYY HH:MI AM') - to_date('12/31/2017 10:00 PM', 'MM/DD/YYYY HH:MI AM')) * 24))+1
ORDER BY rownum;
Výstup
DT
-----------
12/31 10 PM
12/31 11 PM
01/01 12 AM
01/01 01 AM
01/01 02 AM