Oracle function 个人所得税

起征税3000

create or replace function tax(v_salary in number) return number is
  v_expense number; 
  --本级速算扣除额=上一级最高所得额×(本级税率-上一级税率)+上一级速算扣除数
  v_quick_deduction number := 0;
  v_temp number;
begin
  v_temp := v_salary - 3000;
  if v_temp <= 1500  then
     v_temp := v_temp * 0.05;
   elsif v_temp > 1500 and v_temp <= 4500 then
     v_temp := v_temp * 0.1;
     v_quick_deduction := 1500*(0.1-0.05)  + 0;
   elsif v_temp > 4500 and v_temp <= 9000 then
     v_temp := v_temp * 0.2;
     v_quick_deduction := 4500*(0.2-0.1) + 1500*(0.1-0.05);
   elsif v_temp > 9000 and v_temp <= 35000 then
     v_temp := v_temp * 0.25;
     v_quick_deduction := 9000*(0.25-0.2) + 4500*(0.2-0.1) ;
   elsif v_temp > 35000 and v_temp <= 55000 then
     v_temp := v_temp * 0.3;
     v_quick_deduction := 35000*(0.3-0.25) +  9000*(0.25-0.2);
   elsif v_temp > 55000 and v_temp <= 80000 then
     v_temp := v_temp * 0.35;
     v_quick_deduction := 55000*(0.35-0.3) + 35000*(0.3-0.25);
   elsif v_temp > 80000 then
     v_temp := v_temp * 0.45;
     v_quick_deduction := 80000*(0.45-0.35) + 55000*(0.35-0.3);
   else
     dbms_output.put_line('进来就不收你钱!');
     v_temp := 0;
   end if;
   v_expense := v_temp - v_quick_deduction;
  return(v_expense);
end tax;

测试: select tax(5000) from dual;

结果:125

你可能感兴趣的:(oracle)