'CONTINUE' keyword in Oracle 10g PL/SQL

后端 未结 9 2164
失恋的感觉
失恋的感觉 2020-12-14 06:00

I\'m migrating a TSQL stored procedure to PL/SQL and have encountered a problem - the lack of a CONTINUE keyword in Oracle 10g.

I\'ve read that Oracle 11g has this a

相关标签:
9条回答
  • 2020-12-14 06:52

    Can you refactor the IFs into a function, returning at the appropriate point (early if necessary). Then the control flow will pick up in the loop at the right place.

    Does that make sense?

    0 讨论(0)
  • 2020-12-14 06:53

    Though it's a bit complex and just a fake, you can use exception this way :

    DECLARE
      i NUMBER :=0;
      my_ex exception;
    BEGIN
      FOR i IN 1..10
      LOOP
          BEGIN
             IF i = 5 THEN
                raise my_ex;
             END IF;
             DBMS_OUTPUT.PUT_LINE (i);
          EXCEPTION WHEN my_ex THEN
             NULL;
          END;
      END LOOP;
    
    END;
    
    0 讨论(0)
  • 2020-12-14 06:54

    You can simulate a continue using goto and labels.

    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;
    
    0 讨论(0)
提交回复
热议问题