Oracle10G 循环控制
Oracle 10g PL/SQL语言的for/while循环没有提供类似break/continue之类跳出循环的语句,但是有goto(在C中,goto的名声不太好)。如下:
DECLARE
done BOOLEAN;
BEGIN
FOR i IN 1..50 LOOP
IF done THEN
GOTO end_loop;
END IF;
<<end_loop>> -- not allowed unless an executable statement follows
NULL; -- add NULL statement to avoid error
END LOOP; -- raises an error without the previous NULL
END;
done BOOLEAN;
BEGIN
FOR i IN 1..50 LOOP
IF done THEN
GOTO end_loop;
END IF;
<<end_loop>> -- not allowed unless an executable statement follows
NULL; -- add NULL statement to avoid error
END LOOP; -- raises an error without the previous NULL
END;
在上面的代码中,<<end_loop>>标签后面要接一个NULL;语句,不然运行过程中会出错。按上面的方式跳出循环,算是一种折衷吧!