create or replace function 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; 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 adc_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 '49' then /* ?????? 5/4 ????1??? ??????? 50 ??????? ??????? 50 ?????? ?????????? */ if ldc_fac < 50.00 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 adc_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 ;