存储过程中游标取出的值,我想循环累加这个取出的值,怎么写啊?大家帮看看,先谢了!

解决方案 »

  1.   

    在declare部分声明一个变量,初始化为0,每次fetch出值的时候就加到这个变量上
      

  2.   

    这个我明白 我的意思是这个累加怎么写?我这么写的为什么没起作用?输出
    totalmoney,可是结果是最后一次的值?for allbankMoneyTmp in  allbankMoney loopbegin
         totalmoney:=+allbankMoneyTmp.money;end ;end loop ;
      

  3.   


    declare
      totalscore tablec.score%type;
    begin
      for cur in (select * from tablec) loop
        totalscore := totalscore + cur.score;
      end loop;
    end;
      

  4.   


    DECLARE
      num NUMBER:=0;
    BEGIN
      FOR i IN 1..100 LOOP
        num:=num+i;
      END LOOP;
      Dbms_Output.put_line('num='||num);
    END;     PL/SQL block, executed in 0 sec.
         num=5050                        
         Total execution time 0 sec.     
      

  5.   

    -----------Y的,奇怪了,怎么没值呢?
    SQL> select * from tablec;STUDENT                                                                               SCORE
    -------------------------------------------------------------------------------- ----------
    yjl49                                                                                   100
    sss                                                                                     120SQL> 
    SQL> declare
      2    totalscore tablec.score%type;
      3  begin
      4    for cur in (select * from tablec) loop
      5      totalscore:= totalscore + cur.score;
      6    end loop;
      7    dbms_output.put_line('totalscore'||totalscore);
      8  end;
      9  /totalscorePL/SQL procedure successfully completedSQL> 
      

  6.   

    游标取的值都是一样的 且都是数字的?
    declare
    n number;
    sn number:=0;
    cursor cur is select id from tb;
    begin
    open cur;
    loop
    fetch cur into n
    sn:=sn+n;
    exit when cur%notfound;
    end loop;
    close cur;
    end;
      

  7.   

    declare
    n number;
    sn number:=0;
    cursor cur is select id from tb;
    begin
    open cur;
    loop
    fetch cur into n;
    sn:=sn+n;
    exit when cur%notfound;
    end loop;
    close cur;
    end;
      

  8.   

    NND,莫非和我的盗版数据库有关?