[英]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.我想根据 Oracle sql 中的 sysdat 获取季度和年份。例如,我希望当前季度的预期结果值为
2022q3
。
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'
:您可以使用格式字符串
'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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.