How to write out of loop in Oracle stored procedure

Note: This article comes from: "  Writing Method of Jumping Out of Loop in Oracle Stored Procedure    "




How to write out of loop in Oracle stored procedure


Record the usage of exit and return


1: exit is used to jump out of the loop

  1 loop
  2 IF V_KBP IS NULL THEN
  3           EXIT;
  4    END IF;
  5 end loop;


2: return to jump out of the stored procedure

  1 loop
  2 IF V_KBP IS NULL THEN
  3         return;
  4    END IF;
  5 end loop;


3: Jump out of the loop once

Oracle 11g has provided continue;
     oracle 10g and below, use goto instead, for example

  1 SQL> set serveroutput on;
  2 SQL> declare
  3   2  begin
  4   3    for i in 1..10 loop
  5   4      if mod(i,2)=0 then
  6   5        goto next;
  7   6      end if;
  8   7      dbms_output.put_line(i);
  9   8      <<next>>
 10   9      null;
 1110     end loop;
 12 11   end ;
 13 12 /
 14 Note: The null; statement after the << next >> label is indispensable, because the goto label must be followed by an execution statement
















————————————————————————————————————————————————————————————————————————————————————————————————

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324597758&siteId=291194637