Oracle 循环的三种写法
-- loop -- 1. exit ... when 结束循环 DECLARE v_value NUMBER(8) := -3; BEGIN <<value_loop>> -- 循环标记 LOOP dbms_output.put_line('v_value = ' || v_value); v_value := v_value+1; EXIT value_loop WHEN v_value > 3; END LOOP; dbms_output.put_line('loop循环结束!'); END; -- 2. if ... exit 结束循环 DECLARE v_value NUMBER(8) := -3; BEGIN <<value_loop>> LOOP dbms_output.put_line('value:' || v_value); v_value := v_value +1; IF v_value > 3 THEN dbms_output.put_line('value is larger than 3 , current value is ' || v_value); EXIT value_loop; END IF; END LOOP value_loop; dbms_output.put_line('loop is end'); END; -- while loop 本身有可以结束循环的条件 DECLARE v_value NUMBER(8) := -3; BEGIN <<while_loop>> WHILE(v_value < 4) LOOP dbms_output.put_line('value is ' || v_value); v_value := v_value + 1; END LOOP while_loop; dbms_output.put_line('while loop is end'); END; -- for...loop BEGIN FOR v_value IN -3..3 LOOP dbms_output.put_line('value is ' || v_value); END LOOP ; dbms_output.put_line('for loop is end'); END;