Gagnon, Here is an example (using DB2 syntax but the basic concept of the CTE is the same).
Code:
WITH HOUR_TAB (HH)
AS (SELECT 0 FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT HH + 1 FROM HOUR_TAB
WHERE HH < 23
)
, MIN_TAB (MN)
AS (SELECT 0 FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT MN + 5 FROM MIN_TAB
WHERE MN < 55
)
SELECT CAST(CASE WHEN HH BETWEEN 0 AND 9 THEN '0' || HH ELSE '' || HH END AS CHAR(2))
|| ':'
|| CAST(CASE WHEN MN BETWEEN 0 AND 9 THEN '0' || MN ELSE '' || MN END AS CHAR(2))
|| ':00.000000'
FROM HOUR_TAB
, MIN_TAB
ORDER BY 1
You can remove the FROM SYSIBM.SYSDUMMY1 and the various formatting I did to get the proper output.
The basic concept is 2 CTE queries. One to generate a list of Hours (0-23) and one for Minutes (0-55 at 5 minute intervals).
The main query joins the 2 CTE 'table' without a join predicate (which you normally don't want but in this case it works for you) to apply every set of Minutes to every set of Hours.
Code:
00:00:00.000000
00:05:00.000000
00:10:00.000000
00:15:00.000000
00:20:00.000000
00:25:00.000000
00:30:00.000000
00:35:00.000000
00:40:00.000000
00:45:00.000000
00:50:00.000000
00:55:00.000000
01:00:00.000000
01:05:00.000000
01:10:00.000000
01:15:00.000000
(list truncated to save space)
22:35:00.000000
22:40:00.000000
22:45:00.000000
22:50:00.000000
22:55:00.000000
23:00:00.000000
23:05:00.000000
23:10:00.000000
23:15:00.000000
23:20:00.000000
23:25:00.000000
23:30:00.000000
23:35:00.000000
23:40:00.000000
23:45:00.000000
23:50:00.000000
23:55:00.000000
The intervals can be tweaked by changing the amount added.
If you Seconds, you can use a third CTE to generate a seconds list.
PS you can make the main query a CTE since you probably want to Left Outer Join it to another table.