日期:2014-05-17  浏览次数:20781 次

这个存储过成那里有错!!怎么老不行
CREATE OR REPLACE
procedure UpdateSHGL_CJ(
 i_cjrq in date,
 i_hm in varchar(20),
 i_dqbh in number,
 i_hmlb in char(1),
 i_wxcj in number(10,2),
 i_bdhf in number(10,2),
 i_bdct in number(10,2),
 i_bdgj in number(10,2),
 i_yhl in number(10,2),
 i_dlsbh_sb in number(10,2)
)
as
begin
set serveroutput on 
declare 
 h1 number(10,2):=0.49;
 s1 number(10,2):=0.41;
 h2 number(10,2):=0.25;
 s2 number(10,2):=0.25;
 A1 number(10,2):=i_bdhf;
 B1 number(10,2):=i_bdgj;
 C1 number(10,2):=i_bdct;
 D1 number(10,2):=i_yhl;
 F1 int:=100000;
 G1 int:=100;
 I1 number(10,2):=0.05;
 F2 int:=200000;
 G2 int:=100;
 I2 number(10,2):=0.10;
 E1 int:=30;
 E2 int:=60;
 i_yfcj number(10,2):=0.00;
 i_hmcj number(10,2):=0.00;
 i_sbcj number(10,2):=0.00;
 i_dlsbh number:=0;
 i_sbdls number:=0;
 i_hmcj number(10,2);
 i_sbcj number(10,2);
 total1 number(10,2):=A1+B1+C1;
 total2 number(10,2):=i_bdct+(1/(3*B1));
 total3 number(10,2):=(1-D1)*total1;
 begin
---------------------------------------
select sum(dlsbh)into i_dlsbh from SHGL_CJQD where cjrq=i_cjrq;
select sum(dlsbh_sb)into i_sbdls from SHGL_CJQD where cjrq=i_cjrq;
-------------------------------------------
if i_hmlb='1' then
  if total2 >=E1 then
  i_hmcj:=H1 * total3;
  i_sbcj:=S1* total3;
  end if;
 else 
  if total1>=F2 then
  if total1 >= G2 then
  i_hmcj:=(H2+I2)*total1;
  i_sbcj:=S2*total1;
  end if;
  if (total2>=E2 and total<G2) or (i_dls=i_sbdls) then
  i_hmcj:=H2*total1;
  i_sbcj:=S2*total1;
  end if;
  end if;
  if total1>=F1 and total1<F2 then
  if total1 >=G1 then
  i_hmcj:= (H2+I1)*total1;
  i_sbcj:=S2*total1;
  end if;
  if (total2>=E2 and total2<G1)or (i_dls=i_sbdls) then
  i_hmcj:=H2 * total1;
  i_sbcj:=S2*total1;
  end if;
  end if;
  if total1<F1 then
  i_hmcj:=H2*total1;
  i_sbcj:=S2*total1;
  end if;
 end if;
 --------------------------
 if i_dls=i_sbdls then
  i_yfcj:=i_hmcj+i_sbcj;
 else
  i_yfcj:=i_hmcj;
 end if;
 ---------------------------------
 update SHGL_CJQD
 set
  total=total1,
  yfcj=i_yfcj,
  hmcj=i_hmcj,
  sbcj=i_sbcj
 where hm=i_hm;
 end;
end;


------解决方案--------------------
1.仔细将if...else...end if一个一个语句块对齐分析一下, 画个流程图. 看结出的代码上看有多处有两组if处于同一分枝上.

2. 对于select ...into ..from ..., 其结果只能有一条, 若无数据或多条数据时会产生错误.
------解决方案--------------------
过程开始处的参数定义只需要定义类型,不能定义长度;把as和declare之间的两行删除。
------解决方案--------------------
要删除一个END