The development of the project needs to use a query for the first day of the week Date function search n long hard to find a solution as long as you write a first with the code as follows A_week format for ' yyyyiw ' as ' 200801 ' for the first week of 2008
Week use IW method to calculate if there are more than or equal to 4 days after the 52nd Zhou Bie of the Year and the year of December 31, then the 53rd week of the year, otherwise the remaining days will be classified as the 1th week of the following year
1 CREATE OR REPLACE FUNCTION f_week_to_date (a_week varchar2) RETURN char is 2 v_first_date CHAR (ten); 3 V_date_of_week number (1); 4 5 BEGIN 6 Select To_char (To_date (substr (A_week, 1, 4) | | ' 0101 ', ' yyyymmdd '), ' D ') 7 to V_date_of_week 8 from dual; 9 V_date_of_week: = v_date_of_week-1; if V_date_of_week <= 4 then one select To_char (To_date (SUBSTR (A_week, 1, 4) | | ' 0101 ', ' yyyymmdd ') + SUBSTR (A_week, 5, 2) * 7-7-V_date_of_week + 1, ' yyyy-mm-dd ') 14
into v_first_date from dual; 1 Else + Select To_char (To_date (SUBSTR (A_week,, 4) | | ' 0101 ', ' yyyymmdd ') + SUBSTR (A_week, 5, 2) * 7 -V_date_of_week + 1, ' yyyy-mm-dd ') From V_first_date to dual; End If; v_first_date return; The END;
Oracle queries the first day of the week date