C#中给在循环中给一个值累加可以用 A += A; 在存储过程中应该怎么写呢?

解决方案 »

  1.   

    举个简单的例子,请参考declare 
      -- Local variables here
      i integer := 0;
    begin
      -- Test statements here
      for indx in (select * from test1) loop
        i := i + 1;
      end loop;
      
      dbms_output.put_line(i);
    end;
      

  2.   

      不是你想的那样i:=i+1;
      在循环中我查了一个表得出一个number值这个值不是固定的1,
      比如我查出来了一个值是4用A表示,我要把4赋值给 i;
      继续循环,又查出来一个值是9还是A表示,接着把9留给i;这个时候跳出循环
      i 最后的结果为13, 这个i应该怎样算
      如果是在C#中循环中可以用 i += A ;
      跳出循环i的值就是13,但是在存储过程中这里的语法应改是什么样的?
      

  3.   


    declare 
      -- Local variables here
      salary_total number := 0;
    begin
      -- Test statements here
      for r in (select salary from emp) loop
        salary_total := salary_total + r.sal;
        --如果需要达到某值时退出循环,加上下面判断
        if salary_total > 10000 then
          exit;
        end if;
      end loop;
      
      dbms_output.put_line('总薪水:'||to_char(salary_total));
    end;
      

  4.   

    for r in (select salary from emp) loop   这里的salary应该是sal,笔误
      

  5.   


     i number(2);
     j number(8);
     h number(10);
     WHILE  i <= 10 LOOP
      select count(*) into j from table where lx = i;
      h:=j; --就是这一句不会写,如果按照这样的话,每次查的j值都赋给了h;我想要总的h的和;
             --在C#中可以用 h+=j这样最后跳出循环那到h就是所有查处的j的总和,
             --但在oracle存储过程中应该怎样写?累加的语法是什么呢?
      i:=i+1;
     END LOOP;
     select * from table2 where lbzs = h;
     --这里用到的h是上边循环j的总和。
      

  6.   


    ...
    h:=j; 改成 h := h + j;
    ...