Option 1: NLS_TERRITORY
session parameter
In Oracle, the day of the week depends on the NLS_TERRITORY
session setting:
SELECT TO_CHAR(DATE '2022-12-11', 'D') AS day, -- a sunday
(SELECT value FROM NLS_SESSION_PARAMETERS WHERE parameter = 'NLS_TERRITORY')
AS territory
FROM DUAL;
Outputs different values for different parameters. I.e., if you use:
ALTER SESSION SET NLS_TERRITORY='America';
ALTER SESSION SET NLS_TERRITORY='Germany';
ALTER SESSION SET NLS_TERRITORY='India';
ALTER SESSION SET NLS_TERRITORY='Oman';
ALTER SESSION SET NLS_TERRITORY='Bangladesh';
and run the query for each then the outputs are:
DAY |
TERRITORY |
1 |
AMERICA |
7 |
GERMANY |
1 |
INDIA |
2 |
OMAN |
3 |
BANGLADESH |
So you could just pick the correct territory for your database, i.e.:
ALTER SESSION SET NLS_TERRITORY='India';
Option 2: Compare to the start of the ISO-week
Or if you want to be independent of the session settings then you can compare it to the start of the ISO-week (which is always midnight Monday) and offset by one day to change the comparison from Monday-Sunday to Sunday-Saturday:
SELECT TRUNC(SYSDATE + 1) - TRUNC(SYSDATE + 1, 'IW') + 1 AS day
FROM DUAL;
Which, for today (Friday) outputs:
fiddle