如何存储过程中如何遍历一个表

SQL Server:
declare @name varchar(30);  
declare my_cursor SCROLL cursor for select ProductName from kuailegu.tb_Product;  
open my_cursor;  
fetch my_cursor into @name;  
WHILE (@@fetch_status = 0) 
begin  
FETCH NEXT FROM my_cursor INTO @name;  
print @name;  
end  
CLOSE my_cursor  
DEALLOCATE my_cursor

 

Oracle版本:  
  declare  
      cursor   getrecord   is   select   name   from   table;  
      myname   vachar2(30);  
  begin  
      open   getrecord;  
      loop    
            fetch   getrecord   into   myname;  
            exIT   when   getrecord%notfound;  
            ....  
      end   loop;  
      close   getrecord;  
  end;

 

 

posted on 2009-07-06 10:47  韩显川  阅读(2943)  评论(1编辑  收藏  举报

导航