create or replace function ft_roundmoney( adc_money number , as_coopid char , as_applgroup char , as_function varchar2 ) return number is ls_satangtyp char(2); ls_roundtyp char(1); li_trunamt number(1,0); li_roundamt number(1,0); ldc_fac number(3,2); ldc_rdamt number(3,2); ldc_point1 number(3,2); ldc_point2 number(3,2); ldc_integer number(20,7); ldc_money number(20,7); begin ldc_money := adc_money; /* select satang_type , truncate_pos_amt , round_type , round_pos_amt into ls_satangtyp , li_trunamt , ls_roundtyp , li_roundamt from cmroundmoney where upper(branch_id) = upper(as_branchid) and upper(applgroup_code) = upper(as_applgroup) and upper(function_code) = upper(as_function) and use_flag = 1*/ select satang_type , truncate_pos_amt , round_type , round_pos_amt into ls_satangtyp , li_trunamt , ls_roundtyp , li_roundamt from ( select satang_type , truncate_pos_amt , round_type , round_pos_amt , 2 as sort from cmroundmoney where coop_id = as_coopid and applgroup_code = as_applgroup and function_code = 'ALL' and use_flag = 1 union select satang_type , truncate_pos_amt , round_type , round_pos_amt , 1 as sort from cmroundmoney where coop_id = as_coopid and applgroup_code = as_applgroup and function_code = as_function and use_flag = 1 ) cmrd where rownum = 1 order by sort; /*Exception When no_data_found then Begin dbms_output.put_line('no_data_found'); select satang_type , truncate_pos_amt , round_type , round_pos_amt into ls_satangtyp , li_trunamt , ls_roundtyp , li_roundamt from cmroundmoney where upper(branch_id) = upper(as_branchid) and upper(applgroup_code) = upper(as_applgroup) and upper(function_code) = 'ALL' and use_flag = 1; End; When others then Begin dbms_output.put_line('others'); End;*/ dbms_output.put_line('coop_id='||as_coopid); dbms_output.put_line('applgroup_code='||as_applgroup); dbms_output.put_line('function_code='||as_function); dbms_output.put_line('satang_type='||ls_satangtyp); dbms_output.put_line('truncate_pos_amt='||li_trunamt); dbms_output.put_line('round_type='||ls_roundtyp); dbms_output.put_line('round_pos_amt='||li_roundamt); ldc_money := trunc( ldc_money , li_trunamt ); dbms_output.put_line('Money_trunc(0)='||ldc_money); for li_trunct in reverse li_roundamt..li_trunamt loop ldc_money := round( ldc_money , li_trunct ); dbms_output.put_line('Money_trunc('||li_trunct||')='||ldc_money); end loop; ldc_integer := trunc( ldc_money , 0 ); ldc_fac := ldc_money - ldc_integer; dbms_output.put_line('Fac='||ldc_fac); ldc_point1 := trunc( ldc_fac , 1 ); dbms_output.put_line('Point1='||ldc_point1); ldc_point2 := ldc_fac - ldc_point1; dbms_output.put_line('Point2='||ldc_point2); case ls_satangtyp when '00' then /*??????????*/ return ldc_money; when '10' then /*??????????? 5 ?????*/ if ldc_point2 = 0.00 or ldc_point2 = 0.05 then return ldc_money; elsif ldc_point2 >= 0.01 and ldc_point2 <= 0.04 then ldc_point2 := 0.05; elsif ldc_point2 >= 0.06 and ldc_point2 <= 0.09 then ldc_point2 := 0.1; end if; dbms_output.put_line('10Point1='||ldc_point1); dbms_output.put_line('10Point2='||ldc_point2); ldc_rdamt := ldc_point1 + ldc_point2; when '11' then /*??????????? 10 ?????*/ if ldc_point2 = 0.00 then return ldc_money; else ldc_point2 := 0.1; end if; ldc_rdamt := ldc_point1 + ldc_point2; when '12' then /*??????????? 25 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.25 then ldc_rdamt := 0.25; elsif ldc_fac >= 0.26 and ldc_fac <= 0.50 then ldc_rdamt := 0.50; elsif ldc_fac >= 0.51 and ldc_fac <= 0.75 then ldc_rdamt := 0.75; elsif ldc_fac >= 0.76 and ldc_fac <= 0.99 then ldc_rdamt := 1; else ldc_rdamt := 0; end if; when '13' then /*??????????? 50 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.50 then ldc_rdamt := 0.50; elsif ldc_fac >= 0.51 and ldc_fac <= 0.99 then ldc_rdamt := 1; else ldc_rdamt := 0; end if; when '14' then /*??????????? 1 ???*/ if ldc_fac > 0.00 then ldc_rdamt := 1; else ldc_rdamt := 0; end if; when '48' then /* ?????? 5/4 ????0.05??? ??????? 0.05 ?????? ?????? 0.05 ?????? ??? 0.10 ??? */ if ldc_point2 < 0.05 then ldc_point2 := 0; elsif ldc_point2 = 0.05 then ldc_point2 := 0.05; else ldc_point2 := 1; end if; ldc_rdamt := ldc_point1 + ldc_point2; when '49' then /* ?????? 5/4 ????1??? ??????? 0.50 ?????? ?????? 0.50 ?????? ?????????? */ if ldc_fac < 0.50 then ldc_rdamt := 0; else ldc_rdamt := 1; end if; when '50' then /*???????? 5 ?????*/ if ldc_point2 = 0.00 or ldc_point2 = 0.05 then return ldc_money; elsif ldc_point2 >= 0.01 and ldc_point2 <= 0.04 then ldc_point2 := 0.00; elsif ldc_point2 >= 0.06 and ldc_point2 <= 0.09 then ldc_point2 := 0.05; end if; dbms_output.put_line('51Point1='||ldc_point1); dbms_output.put_line('51Point2='||ldc_point2); ldc_rdamt := ldc_point1 + ldc_point2; when '51' then /*???????? 10 ?????*/ if ldc_point2 = 0.00 then return ldc_money; else ldc_point2 := 0.00; end if; ldc_rdamt := ldc_point1 + ldc_point2; when '52' then /*???????? 25 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.25 then ldc_rdamt := 0.00; elsif ldc_fac >= 0.26 and ldc_fac <= 0.50 then ldc_rdamt := 0.25; elsif ldc_fac >= 0.51 and ldc_fac <= 0.75 then ldc_rdamt := 0.50; elsif ldc_fac >= 0.76 and ldc_fac <= 0.99 then ldc_rdamt := 0.75; else ldc_rdamt := 0; end if; when '53' then /*???????? 50 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.50 then ldc_rdamt := 0.00; elsif ldc_fac >= 0.51 and ldc_fac <= 0.99 then ldc_rdamt := 0.50; else ldc_rdamt := 0; end if; when '54' then /*???????? 1 ???*/ ldc_rdamt := 0; else ldc_rdamt := ldc_fac; end case; ldc_integer := ldc_integer + ldc_rdamt; return ldc_integer; end ;