/*
desription Get the week of before first sunday.
parameter vd_first_week_date
*/
if vd_deal_date < vd_first_week_date then
/*
desription Get the last week of last year when first week start with Jan 1st.
*/
if to_char(to_date(to_char(vd_deal_date,'yyyy') - 1||'0101','yyyymmdd'),'D') = '1' then
ov_return := to_char(to_date(to_char(vd_deal_date,'yyyy') - 1||'1231','yyyymmdd'),'yyyyww');
else
/*
desription Get the date of the first sunday of last year.
*/
vi_loop_num := 1;
loop
if vi_loop_num > 6 then
exit;
else
if to_char(to_date(to_char(vd_deal_date,'yyyy') - 1||'0101','yyyymmdd')+vi_loop_num,'D') = 1 then
vd_first_week_date1 := to_date(to_char(vd_deal_date,'yyyy') - 1||'0101','yyyymmdd')+vi_loop_num;
exit;
else
vi_loop_num := vi_loop_num+1;
desription Get the week of before first sunday.
parameter vd_first_week_date
*/
if vd_deal_date < vd_first_week_date then
/*
desription Get the last week of last year when first week start with Jan 1st.
*/
if to_char(to_date(to_char(vd_deal_date,'yyyy') - 1||'0101','yyyymmdd'),'D') = '1' then
ov_return := to_char(to_date(to_char(vd_deal_date,'yyyy') - 1||'1231','yyyymmdd'),'yyyyww');
else
/*
desription Get the date of the first sunday of last year.
*/
vi_loop_num := 1;
loop
if vi_loop_num > 6 then
exit;
else
if to_char(to_date(to_char(vd_deal_date,'yyyy') - 1||'0101','yyyymmdd')+vi_loop_num,'D') = 1 then
vd_first_week_date1 := to_date(to_char(vd_deal_date,'yyyy') - 1||'0101','yyyymmdd')+vi_loop_num;
exit;
else
vi_loop_num := vi_loop_num+1;