带有sql游标的无限循环(Oracle 10)

时间:2015-04-28 17:29:03

标签: sql oracle cursor plsqldeveloper

我有一个无限循环的光标:

DECLARE
  CURSOR cursor_ab IS
    SELECT num_ab FROM abonne;
BEGIN
  OPEN cursor_ab;
  LOOP
  FETCH cursor_ab INTO numeroAb;
    dbms_output.put_line(numeroAb);
  END LOOP;
  CLOSE cursor_ab;
END;
/

你有什么想法吗?

感谢,

2 个答案:

答案 0 :(得分:3)

你需要退出: 当cursor_ab%NOTFOUND;

时退出

HTH

答案 1 :(得分:2)

正如已经指出的那样,当以这种方式编写循环时,您需要指定退出条件:

DECLARE
   CURSOR cursor_ab IS
      SELECT num_ab FROM abonne;
BEGIN
   FOR numeroab IN cursor_ab LOOP
      DBMS_OUTPUT.put_line (numeroab.num_ab);
   END LOOP;
END;
/

但是,您可以通过让循环管理游标来完成PL / SQL中的相同操作:

Dim ctrl As Control

For Each ctrl In Me.Controls
   If (ctrl.GetType() Is GetType(TextBox)) Then
      If(ctrl.Name.StartsWith("textBoxArray") Then
          'your code here
      End If
   End If
Next