将日期截断到会计年度

2021-12-30 00:00:00 sql oracle11g oracle truncate

以下数据库视图将日期截断为会计年度(4 月 1 日):

The following database view truncates the date to the fiscal year (April 1st):

CREATE OR REPLACE VIEW FISCAL_YEAR_VW AS
SELECT
  CASE
    WHEN to_number(to_char(SYSDATE, 'MM')) < 4 THEN    
      to_date('1-APR-'||to_char(add_months(SYSDATE, -12), 'YYYY'), 'dd-MON-yyyy')
    ELSE
      to_date('1-APR-'||to_char(SYSDATE, 'YYYY'), 'dd-MON-yyyy')
  END AS fiscal_year
FROM
  dual;

这使我们能够根据今天的日期计算当前财政年度.

This allows us to calculate the current fiscal year based on today's date.

如何简化或优化此计算?

How can this calculation be simplified or optimized?

推荐答案

ADD_MONTHS(TRUNC(ADD_MONTHS(SYSDATE,-3),'YYYY'),3)

相关文章