c#里有for循环语句,但存储过程里没有,只有WHILE,有时候while不是很方便,
我想问存储过程中有没有与for相似功能的循环语句,简单一点的

解决方案 »

  1.   

    我截取了orale中的procedure的一部分循环loop
          fetch c_sales_bonus
            into v_storecode, v_staffcode, v_title, v_bonus;
        
          insert into hr_bonus
            (staffcode, storecode, bonus_month, bonus, title, issales)
          values
            (v_staffcode, v_storecode, p_month, v_bonus, v_title, 'Y');
        
          exit when c_sales_bonus%notfound;
        end loop;
      

  2.   

    呵呵,循环好像只能使用while
    declare @count int
    set @count=1
    while(@count!=200)
    {
    print @count;
    set @count=@conut+1
    }
      

  3.   

    loop循环:
    create or replace procedure pro_test_loop is
    i number;
    begin
    i:=0;
    loop
      i:=i+1;
      dbms_output.put_line(i);
      if i>5 then
        exit;
      end if;
    end loop;
    end pro_test_loop;while循环:
    create or replace procedure pro_test_while is
    i number;
    begin
    i:=0;
    while i<5 loop
      i:=i+1;
      dbms_output.put_line(i);
    end loop;
    end pro_test_while;for循环1:
    create or replace procedure pro_test_for is
    i number;
    begin
    i:=0;
    for i in 1..5 loop
      dbms_output.put_line(i);
    end loop;
    end pro_test_for;for循环2:
    create or replace procedure pro_test_cursor is
    userRow t_user%rowtype;
    cursor userRows is
    select * from t_user;
    begin
    for userRow in userRows loop
        dbms_output.put_line(userRow.Id||','||userRow.Name||','||userRows%rowcount);
    end loop;
    end pro_test_cursor; 
      

  4.   

    以上基于oracle数据库,ms sql存储过程里面也是可以循环的
      

  5.   

    没有,没有集合的概念,你怎么用for啊
    要是不行就用C#写DLL,来调用 
      

  6.   

    我要的是在MSSQL里实现的,不然我写的SQL要嵌套好过层才能实现一个查询
    那么存储过程中还有没有其他的循环语句
      

  7.   

    while 跟 for 循环几乎是相同的
    可直接写循环,或使用游标
      

  8.   

    while比for灵活,可以用for的地方都可以用while代替,这有啥问题?
      

  9.   

    ms sql:举个例子吧:declare   @i   int,@j   int   
      select   @i=0   
      while   @i<=9   
          begin   
                set   @j=0   
        
                while   @j<=9   
                    begin   
                            insert   into   temp3   select   @i,@j   
                          set   @j=@j+1   
                    end   
              
            set   @i=@i+1   
      end   
        
      

  10.   

    WHILE FOR DO WHILE
     3个的区别是什么 既然能混合使用 几乎没区别
     只是使用的地方不一样
     貌似有点像IF 和SWITCH.
     使用的地方不一样而已
      换一个用不是不可以.只是添加点复杂度.