例子
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.