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;
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.