我想在oracle上制定还款计划。
这里我创建了两个表
Fund_disburse
create table fund_disburse
(
area_code CHAR (2),
branch_code char (5),
comp_code CHAR (3),
dafa_no CHAR (2),
disburse_date date,
fund_amt NUMBER (20,2),
sc_amt NUMBER(15,2),
Inst_start_date date,
Inst_end_date date,
TTL_INST_NO_PAID NUMBER (2),
TTL_INST_AMT_PAID NUMBER (20,2),
ttl_outs number (20,2) ,
ttl_overd number (20,2),
ttl_adv number (20,2),
ful_pay_flag CHAR(1)) ;
CONSTRAINT "FUND_DISBURSE_PK"
PRIMARY KEY ("AREA_CODE", "BRANCH_CODE", "COMP_CODE", "DAFA_NO")
基金偿还时间表
create table f_repay_schedule
(
area_code CHAR (2),
branch_code char (5),
comp_code CHAR (3),
dafa_no CHAR (2),
Install_no NUMBER (2),
Install_date date,
MNYR VARCHAR2 (8),
Install_amt NUMBER (20,2),
prn_amt NUMBER (15,2),
sc_amt NUMBER (12,2));
CONSTRAINT "F_REPAY_SCHEDULE_FK1"
FOREIGN KEY ("AREA_CODE", "BRANCH_CODE", "COMP_CODE", "DAFA_NO")
REFERENCES "RINFO"."FUND_DISBURSE" ("AREA_CODE", "BRANCH_CODE", "COMP_CODE", "DAFA_NO")
当我在fund_disburse上插入时,还款计划将在f_repay_schedule表中生成。我怎么能这样做?
我也试过通过plsql来做,就像,
declare
k NUMBER := 0;
DISBURSE_AMOUNT number (10) :=&DISBURSE_AMOUNT;
TTL_LOAN_AMT NUMBER (10) := DISBURSE_AMOUNT*1.13;
DAILY_RCVL number (10) := DISBURSE_AMOUNT/1000*25;
PRN_AMT NUMBER (10) := DAILY_RCVL/1.13;
SC_AMT NUMBER (10) := DAILY_RCVL - PRN_AMT;
lAST_INS_AMT NUMBER (10) := TTL_LOAN_AMT - DAILY_RCVL*45;
INST_NO NUMBER (2) := 0;
INST_DATE DATE := SYSDATE;
begin
loop
k := DAILY_RCVL +0;
TTL_LOAN_AMT := TTL_LOAN_AMT - DAILY_RCVL;
INST_NO := INST_NO +1;
INST_DATE := INST_DATE + 7;
DBMS_OUTPUT.PUT_LINE('DATE '||INST_DATE);
DBMS_OUTPUT.PUT_LINE('INSTALLMWNT NO '||INST_NO);
DBMS_OUTPUT.PUT_LINE(' Daily RCV '||k);
DBMS_OUTPUT.PUT_LINE('PRINCIPLE AMOUNT: '||PRN_AMT);
DBMS_OUTPUT.PUT_LINE('SERVICE CHARGE: '||SC_AMT);
DBMS_OUTPUT.PUT_LINE('Loan AMOUNT AFTER RCV: '||TTL_LOAN_AMT);
EXIT WHEN TTL_LOAN_AMT < DAILY_RCVL;
END LOOP;
DBMS_OUTPUT.PUT_LINE('LAST INSTALLMENT AMT: '|| lAST_INS_AMT);
end;
/
但我想,它会与那些表格数据一起使用。
我解决了我的第一个问题。 现在又出现了另一个问题。当我试图在资金支出上插入另一行时 显示错误 &#34;确切的提取返回超过请求的行数&#34; 我的触发器是
create or replace TRIGGER LOAN_RP
AFTER INSERT OR UPDATE ON FUND_DISBURSE
REFERENCING OLD AS NEW OLD AS OLD
DECLARE
V_FA NUMBER (10);
V_RC NUMBER (10);
V_AC CHAR (2);
V_BC CHAR (5);
V_CC CHAR (3);
V_DN CHAR (2);
V_PRN NUMBER (15,2);
V_SC NUMBER (15,2);
V_INSN NUMBER (2) :=0;
V_INSD DATE;
V_RAMT NUMBER (15,2);
BEGIN
SELECT AREA_CODE, BRANCH_CODE, COMP_CODE, DAFA_NO, DISBURSE_DATE, FUND_AMT
INTO V_AC, V_BC, V_CC, V_DN, V_INSD, V_FA
FROM FUND_DISBURSE;
V_RAMT := V_FA*1.13;
V_INSD := (V_INSD-7) + 14;
for i in 1..50 loop
V_INSD := V_INSD+7;
V_RC := V_FA/1000*25;
V_PRN := V_RC/1.13;
V_SC := V_RC - V_PRN;
V_INSN := V_INSN + 1;
V_RAMT := V_RAMT - V_RC;
DBMS_OUTPUT.PUT_LINE(V_RC);
INSERT INTO F_REPAY_SCHEDULE
(AREA_CODE, BRANCH_CODE, COMP_CODE, DAFA_NO, INSTALL_NO,
INSTALL_DATE, INSTALL_AT, PRN_AMT, SC_AMT)
VALUES
(V_AC, V_BC, V_CC, V_DN, V_INSN,
V_INSD, V_RC, V_PRN, V_SC );
EXIT WHEN V_RAMT < V_RC;
END LOOP;
END;
/