一、过程
declare
v_jkrgrzh varchar(10):='0003037350';
v_jcsjxs decimal(18,2):=0;
v_dwjjblxs decimal(18,2):=0;
v_lxhjys decimal(18,2):=0;
begin
v_lxhjys := f_hfb_jcr_getlxhjys(v_jkrgrzh,to_char(sysdate,'yyyymm'));
f_hfb_jcr_get_jcxs(v_jkrgrzh,v_jcsjxs,v_dwjjblxs);
dbms_output.put_line(v_jcsjxs);
dbms_output.put_line(v_dwjjblxs);
dbms_output.put_line(v_lxhjys);
end;
二、函数
create or replace function f_hfb_jcr_getlxhjys
(
v_grzh varchar, --账号
v_yd varchar --月度
)
return integer
as
v_minyd varchar(6);
v_j smallint:= 0;
v_yd0 varchar(6);
v_cnt smallint:= 0;
v_hjys smallint:=0;
begin
select count(*) into v_cnt from
(
select * from im_zj_ls where zhlb='02' and ywfl='01' and ywlx='01' and zh=v_grzh
/*union
select * from syy30_nmgbt_lsnd.im_zj_ls where zhlb='02' and ywfl='01' and ywlx='01' and zh=v_grzh*/);
if v_cnt>0 then
select substr(min(ywyd),0,6) into v_minyd from
(
select * from im_zj_ls where zhlb='02' and ywfl='01' and ywlx='01' and zh=v_grzh
/*union
select * from syy30_nmgbt_lsnd.im_zj_ls where zhlb='02' and ywfl='01' and ywlx='01' and zh=v_grzh*/);
else
v_minyd:='111111';
end if;
select to_char(add_months(to_date(v_yd||'01','yyyymmdd'),0),'yyyymm') into v_yd0 from dual;
v_hjys:=0;
while v_minyd<=v_yd0 loop
select count(*) into v_j from
(select * from im_zj_ls where zhlb='02' and ywfl='01' and ywlx='01' and zh=v_grzh
/*union
select * from syy30_nmgbt_lsnd.im_zj_ls where zhlb='02' and ywfl='01' and ywlx='01' and zh=v_grzh*/) where ywyd=v_yd0;
if v_j<>0 then
v_hjys:=v_hjys+1;
else
exit;
end if;
v_yd0 := to_char(add_months(to_date(v_yd0||'01','yyyymmdd'),-1),'yyyymm');
end loop;
return v_hjys;
end;
三、存储
create or replace procedure f_hfb_jcr_get_jcxs --获取系数
(
v_grzh varchar, --账号
v_jcsjxs in out number, --时间系数
v_dwjjblxs in out number --比例系数
)
as
v_minyd varchar(6);
v_lxhjys smallint:= 0;--月数
v_jcsjxs1 decimal(18,2):=0;
v_dwjjblxs1 decimal(18,2):=0;
v_dwjcbl decimal(18,2):=0;
v_cnt smallint:= 0;
v_hjys smallint:=0;
begin
select f_hfb_jcr_getlxhjys(v_grzh,to_char(add_months(sysdate,-1),'yyyymm')) into v_lxhjys from dual;
if v_lxhjys < 12 then
v_jcsjxs1:=0.8;
elsif v_lxhjys >= 12
v_jcsjxs1:=1;
end if;
select max(b.dwjcbl) into v_dwjcbl from gr_zz a inner join dw_zz b on a.dwzh = b.dwzh where a.grzh = v_grzh;
if v_dwjcbl < 0.08 then
v_dwjjblxs1:=0.1;
elsif v_dwjcbl >= 0.08 and v_dwjcbl < 0.12 then
v_dwjjblxs1:=0.5;
elsif v_dwjcbl >= 0.12 then
v_dwjjblxs1:=1;
end if;
v_jcsjxs:=v_jcsjxs1;
v_dwjjblxs:=v_dwjjblxs1;
end;