简体   繁体   中英

How to get year and quarter for sysdate in Oracle Sql

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM