Установка Oracle :
CREATE TABLE GL_PERIODS(
period_set_name VARCHAR2(20),
start_date DATE,
end_date DATE,
period_name CHAR(6) GENERATED ALWAYS AS ( CAST( TO_CHAR( end_date, 'MON-YY' ) AS CHAR(6) ) ) VIRTUAL,
entered_period_name CHAR(3) GENERATED ALWAYS AS ( CAST( TO_CHAR( end_date, 'MON' ) AS CHAR(3) ) ) VIRTUAL,
period_year NUMBER(4) GENERATED ALWAYS AS ( EXTRACT( YEAR FROM end_date ) ) VIRTUAL
);
INSERT INTO GL_PERIODS( period_set_name, start_date, end_date )
SELECT 'Fiscal Year', DATE '2018-07-29', DATE '2018-08-25' FROM DUAL UNION ALL
SELECT 'Fiscal Year', DATE '2018-08-26', DATE '2018-09-22' FROM DUAL UNION ALL
SELECT 'Fiscal Year', DATE '2018-09-23', DATE '2018-10-27' FROM DUAL;
Запрос :
SELECT TRUNC( SYSDATE - start_date + 1 ) AS fiscal_day_no
FROM GL_PERIODS
WHERE start_date <= SYSDATE
AND SYSDATE < END_DATE + INTERVAL '1' DAY;
Вывод :
| FISCAL_DAY_NO |
|---------------|
| 20 |