create or replace procedure ZGXT_CK_SPQD(cur out sys_refcursor) is
v_count integer:=0;
P_SPKCL integer(12);
P_SPXSSL integer(12);begin
   select count(1) into v_count from spqd;
   select spkcl into P_SPKCL from ck;
   select spxssl into P_SPXSSL from spqd;
   if v_count<>0 then 
   open cur for 
  'update ck set spkcl=P_SPCKL-P_SPXSSL';
  end if ;
end ZGXT_CK_SPQD;
这个存储过程是希望通过对表ck中的spckl进行修改,这样也可以达到效果吗?

解决方案 »

  1.   


    open cursor for update ?
    --看来你是闲着没事干
    /*
    游标就像一个指针,指向数据表,也指向PGA,
    游标可以返回一条数据,也可以返回多条记录
    它指向的PGA中存储下列数据:
    1.查询语句返回的记录行
    2.查询语句处理的记录数目
    3.指向共享池中已解析查询语句的一个指针
    */
      

  2.   


    请教大虾 ,那这个存储过程要怎么写好呢?然后要在SQL调用,要怎么实现
      

  3.   


    --将你的需求描述清楚点,
    --单看你写的过程怎么知道你想要做啥
    --比如更新表,是部分更新还是全部更新,条件是什么,过程参数是什么......
    create or replace procedure ZGXT_CK_SPQD(cur out sys_refcursor) 
    is
      v_count number(2):=0;
      P_SPKCL number(12);
      P_SPXSSL number(12);begin
      select count(1) into v_count from spqd;--1.这条语句是统计表spqd中的数据行数
      
      select spkcl into P_SPKCL from ck;--2.这sql肯定不成功,一个变量接收多个值
      
      select spxssl into P_SPXSSL from spqd;--3.同2
      
      if v_count<>0 then   
         update ck set spkcl=P_SPCKL-P_SPXSSL;--4.更新语句
         commit;--更新后不要忘记了提交
      end if ;
      --牵涉到数据修改的过程都应该有异常处理
      exception
      when others then
           rollback;--若更新失败或者出现其他意外,回滚
    end ZGXT_CK_SPQD;
      

  4.   

    有2张表,spqd,ck,现在要根据spqd这张表里面的spsxsl(商品销售数量)这个字段里面的值,更新ck表中的spkcl(商品库存量),然后调用存储过程要怎么写呢
      

  5.   

    SQL中最好用FUNCTION来处理。不需要用PROCEDURE。