I want to get the quarter and year depending on the sysdat in Oracle sql.
For example i want expected result value as 2022q3
for current quarter.
I can get the quarter using below query:
select to_char(sysdate, 'Q') as qtr from dual;
CodePudding user response:
You can achieve this with the format string 'YYYY"Q"Q'
:
select to_char(sysdate, 'YYYY"Q"Q') as qtr
from dual
A possible way to get previous quarter:
select to_char(sysdate - interval '3' month, 'YYYY"Q"Q') as qtr
from dual