'All quarters in current year in Oracle SQL
I want to display the quarters in the current year like -
2022 Q 1
2022 Q 2
2022 Q 3
2022 Q 4
Is there any way to do this ? When I am using the below query, I am only getting current quarter -
select to_char(sysdate, 'yyyy" Q "q') as QuaterDate from dual
Solution 1:[1]
You can use a hierarchical query such as
SELECT TO_CHAR(sysdate, 'yyyy" Q "')||level AS QuaterDate
FROM dual
CONNECT BY level <= 4
Solution 2:[2]
Just for fun:
select to_char(sysdate, 'yyyy" Q "') || xmlcast(column_value as number) as qtr
from xmltable('1 to 4')
;
QTR
--------
2022 Q 1
2022 Q 2
2022 Q 3
2022 Q 4
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mathguy |
| Solution 2 | mathguy |
