基本的循环结构在 LOOP 和 END LOOP 语句之间包含语句序列。
Basic LOOP - 语法
PL/SQL编程语言中基本循环的语法是-
LOOP Sequence of statements; END LOOP;
在此,一个或多个语句的序列可以是单个语句或语句块,需要 EXIT语句或 EXIT WHEN语句才能中断循环。
Basic LOOP - 示例
DECLARE x number := 10; BEGIN LOOP dbms_output.put_line(x); x := x + 10; IF x > 50 THEN exit; END IF; END LOOP; -- after exit, control resumes here dbms_output.put_line('After Exit x is: ' || x); END; /
当以上代码在SQL提示符下执行时,将产生以下输出-
10 20 30 40 50 After Exit x is: 60 PL/SQL procedure successfully completed.
您可以使用 EXIT WHEN 语句代替 EXIT 语句-
DECLARE x number := 10; BEGIN LOOP dbms_output.put_line(x); x := x + 10; exit WHEN x > 50; END LOOP; -- after exit, control resumes here dbms_output.put_line('After Exit x is: ' || x); END; /
当以上代码在SQL提示符下执行时,将产生以下输出-
10 20 30 40 50 After Exit x is: 60 PL/SQL procedure successfully completed.
参考链接
https://www.learnfk.com/plsql/plsql-basic-loop.html
标签:语句,10,END,无涯,PL,SQL,put,LOOP From: https://blog.51cto.com/u_14033984/8945290