July 30, 2010, Friday, 210


LEAVE

From SQL PL Guide for DB2

Jump to: navigation, search

LEAVE statement

The LEAVE statement can be used to jump out of a loop or a compound statement.

If the loop or compound statement is nested you should explicit specify the label you want to leave.


Example:

 create procedure leave (in var01 integer, out var02 integer)
 begin
  declare i integer default 0;
  
  my_loop: loop

    if i = var01 then
      leave my_loop;
    else
      set i = i + 1;
    end if;

  end loop;
  set var02 = i;

end!



Link to the DB2 Information Center: DB2 9 DB2 9.5