Chapter 9 SQL Statements
567
LOOP statement
Use this statement to repeat the execution of a statement list.
[
statement-label
: ]
…[ WHILE
search-condition
] LOOP
…
statement-list
…END LOOP [
statement-label
]
None.
None.
"FOR statement" on page 528
"LEAVE statement" on page 558
The WHILE and LOOP statements are control statements that allow you to
execute a list of SQL statements repeatedly while a search-condition
evaluates to TRUE. The LEAVE statement can be used to resume execution
at the first statement after the END LOOP.
If the ending statement-label is specified, it must match the beginning
statement-label.
♦
SQL/92 Persistent Stored Module feature.
♦
Sybase Not supported in Adaptive Server Enterprise. The WHILE
statement provides looping in Transact-SQL stored procedures.
♦ A While loop in a procedure.
...
SET i = 1;
WHILE i <= 10 LOOP
INSERT INTO Counters( number ) VALUES ( i );
SET i = i + 1;
END LOOP;
...
♦ A labeled loop in a procedure.
SET i = 1;
lbl:
LOOP
INSERT
INTO Counters( number )
VALUES ( i );
IF i >= 10 THEN
LEAVE lbl;
END IF;
SET i = i + 1;
END LOOP lbl
Function
Syntax
Permissions
Side effects
See also
Description
Standards and
compatibility
Examples