The Oracle function written for your first time is very simple, but I hope to help everyone.
create or replace function FIRST_LAST_WEEK_DAY (IN_DAY IN DATE, I IN INTEGER) return VARCHAR2 is Result VARCHAR2 (8); J INTEGER; begin / * Get first day first_last_week_day (sysdate, 0) acquired week last day of the week first_last_week_day (sysdate, 1) * / select to_char (in_day, 'd') INTO J from Dual; if i = 0 Then Result: = to_CHAR (IN_DAY - J 1, 'YYYYMMDD'); Else Result: = to_CHAR (In_Day (7 - j), 'YYYYMMDD'); endiff; return; end first_last_week_day;