固定金额的利息配置

时间:2019-01-08 07:01:06

标签: sql oracle plsql

使用sql或plsql从兴趣配置中找到total_charge

START_FROM     END_TO   PER_UNIT    CHAR_PU   MIN_CHAR   MAX_CHAR INSTRUCTION                                       
---------- ---------- ---------- ---------- ---------- ---------- -------------
         0       9999       1000          3         10          0 compare min                                       
     10000      29999       1000        2.5          3          0 add min                                        
     30000      99999       1000          2          0          0 compare                                           
    100000     999999       1000        1.5          0        300 compare max                                       

步骤:

  1. 从用户获取start_from和End_to之间的金额。例。 0-9999数量= 5000
  2. 在验证指令的情况下通过per_unit计算费用。 amount = 5000 charge = 3 per = 1000 total_charge =15。但是在这种情况下,当amount = 2000时total_charge = 6时,我们需要验证指令,并将其与min_Charge = 10和total_charge = 10进行比较。
  3. 在10000-29999验证中,添加min = total_charge + 3
  4. 在适用于Max_charge的100000-999999验证中
  5. 通过“&”获得的金额以及列中显示的total_charges

1 个答案:

答案 0 :(得分:0)

CREATE OR REPLACE FUNCTION calcu(amount NUMBER) RETURN NUMBER is charge NUMBER; BEGIN SELECT ((amount/per_unit)*char_pu) into charge from a where amount between start_from and end_to; if (charge<10) then charge:=10; elsif(amount between 10000 and 29999) then charge:=charge+3; elsif(charge>300) then charge:=300; end if; RETURN charge; END calcu; select calcu(&amount) as charge from dual;