My query is
Select class_time from tableA
which produces:
0200AM 0230AM 0300AM 0330AM 0400AM
i want above result as
0200AM 0230AM 0300AM 0330AM 0400AM 0430AM
Advertisement
Answer
Assuming you are storing the times in a DATE
data type (which always has year, month, day, hour, minute and second components) then add an INTERVAL
literal to the maximum value from the table:
SELECT class_time from tableA UNION ALL SELECT MAX( class_time ) + INTERVAL '30' MINUTE FROM tableA
or add a fraction of a day:
SELECT class_time from tableA UNION ALL SELECT MAX( class_time ) + 30 / ( 24 /* hours */ * 60 /* minutes */ ) FROM tableA
Output:
| CLASS_TIME | | :------------------ | | 2019-12-16 02:00:00 | | 2019-12-16 02:30:00 | | 2019-12-16 03:00:00 | | 2019-12-16 03:30:00 | | 2019-12-16 04:00:00 | | 2019-12-16 04:30:00 |
If your times are stored as strings then convert them to a date, add 30 minutes and then convert back to a string:
SELECT class_time from tableB UNION ALL SELECT TO_CHAR( MAX( TO_DATE( class_time, 'HH12:MI AM' ) ) + INTERVAL '30' MINUTE, 'HH12:MI AM' ) FROM tableB
Output:
| CLASS_TIME | | :--------- | | 02:00 AM | | 02:30 AM | | 03:00 AM | | 03:30 AM | | 04:00 AM | | 04:30 AM |
db<>fiddle here