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

谁帮我解释一下这个存储过程
谁帮我看看这个存储过程,解释一下语法的东西,业务就不用管了
SQL code

create or replace procedure p_ysgl_fkqk(as_year Varchar2) Is
vn_bfje number(22,6);
vs_ysnf Varchar2(4);
vs_ysbh Varchar2(50);
vn_htje number(22,6);

cursor cur_ysgl_fkqk Is Select c_ysnf,c_ysbh,n_bfje_hz,n_htje
--这一句不懂

From
--v_ysgl_fkqk
(select c_ysnf,c_ysbh,sum(nvl(n_bfje,0)) n_bfje_hz,max(nvl(n_ysje_tzsp,0)) n_htje
from tab_bfspb a
where a.c_ysnf=as_year
group by c_ysnf,c_ysbh)
Where c_ysnf=as_year Order By c_ysbh;
--这里()里面的select语句我知道,把它当一个整体后from它是什么意思呢?

Begin
  Update tab_ysgk Set n_ljbfje=null,n_ljye=null where c_ysnf = vs_ysnf;
  Commit;

  open cur_ysgl_fkqk;

----open 是什么意思啊,打开的是什么东西

      loop
        fetch cur_ysgl_fkqk into vs_ysnf,vs_ysbh,vn_bfje,vn_htje;
        exit when cur_ysgl_fkqk%notfound;
        Update tab_ysgk Set n_ljbfje = vn_bfje,n_ljhtje = vn_htje
        Where c_ysbh = vs_ysbh And c_ysnf = vs_ysnf;
        commit;

        Update tab_ysgk Set
        n_ljye = nvl(n_ysje_tzsp,0) - nvl(vn_bfje,0),
        n_ljhtjeye = nvl(n_ljhtje,0) - nvl(vn_bfje,0)
        Where c_ysbh = vs_ysbh And c_ysnf = vs_ysnf;
        commit;
      end loop;

--------这里loop是和上面的loop对应的吗,是不是表示循环,当exit 的条件满足是就跳出了循环

   Close cur_ysgl_fkqk;

   Update tab_ysgk Set n_ljbfje = 0 Where n_isleaf = 1 And n_ljbfje Is Null;
   Update tab_ysgk Set n_ljye = nvl(n_ysje_tzsp,0) - nvl(n_ljbfje,0)
   Where n_isleaf = 1 And n_ljye Is Null;
   Update tab_ysgk Set  n_ljhtje = n_ysje_tzsp Where n_isleaf = 1 And n_ljbfje = 0;
   Commit;
end p_ysgl_fkqk;

----结束的时候语法是怎样的?(end 存储过程名字)????




------解决方案--------------------
cursor cur_ysgl_fkqk Is Select c_ysnf,c_ysbh,n_bfje_hz,n_htje --游标,看下游标是如何用的

open cur_ysgl_fkqk; --打开游标

--这里()里面的select语句我知道,把它当一个整体后from它是什么意思呢? --把这个结果集当张表

这里loop是和上面的loop对应的吗,是不是表示循环,当exit 的条件满足是就跳出了循环 --是的

end p_ysgl_fkqk; --你说的是对的,也可以写成 end;
------解决方案--------------------
cursor cur_ysgl_fkqk Is 是定义游标

open 是打开游标

--------这里loop是和上面的loop对应的吗,是不是表示循环,当exit 的条件满足是就跳出了循环
你理解的正确


最后直接写end就可以了