ITPub博客

首页 > 数据库 > Oracle > PLSQL Language Referenc-FOR循环-FOR循环中的EXIT WHEN和CONTINUE WHEN

PLSQL Language Referenc-FOR循环-FOR循环中的EXIT WHEN和CONTINUE WHEN

原创 Oracle 作者:luisedalian 时间:2014-03-11 07:44:51 0 删除 编辑

FOR循环中的EXIT WHENCONTINUE WHEN

DECLARE

    v_employees employees%ROWTYPE;

    CURSOR c1 is SELECT * FROM employees;

BEGIN

    OPEN c1;

    -- 获取整个行

    FOR i IN 1..10 LOOP

        FETCH c1 INTO v_employees;

        EXIT WHEN c1%NOTFOUND;

        -- 在此处理数据

    END LOOP;

    CLOSE c1;

END;

 

DECLARE

    v_employees employees%ROWTYPE;

    CURSOR c1 is SELECT * FROM employees;

BEGIN

    OPEN c1;

 

    -- 获取整行

    <<outer_loop>>

    FOR i IN 1..10 LOOP

        -- 在此处理数据

        FOR j IN 1..10 LOOP

            FETCH c1 INTO v_employees;

            --直接退出外部循环

            EXIT outer_loop WHEN c1%NOTFOUND;

        -- 在此处理数据

        END LOOP;

    END LOOP outer_loop;

  CLOSE c1;

END;

 


 

--不管表中有多少条记录,循环都做100

DECLARE

    v_employees employees%ROWTYPE;

    CURSOR c1 is SELECT * FROM employees;

BEGIN

    OPEN c1;

 

    <<outer_loop>>

    FOR i IN 1..10 LOOP   

        DBMS_OUTPUT.PUT_LINE('外部循环 i = ' || i);

        FOR j IN 1..10 LOOP

            DBMS_OUTPUT.PUT_LINE('内部循环 j = ' || j);

            FETCH c1 INTO v_employees;

            CONTINUE outer_loop WHEN c1%NOTFOUND;

        END LOOP;

    END LOOP outer_loop;

    CLOSE c1;

END;


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17013648/viewspace-1107112/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-02-06

  • 博文量
    1986
  • 访问量
    5687241