Pregunta

Is there a statement like break that can terminate the while loop in stored procedure? I am now terminating by checking an additional condition but the whole loop have to be nevertheless completed atleast once to check the condition again. Please help me in this regard.

¿Fue útil?

Solución

The while loop does indeed have a break clause which exits the loop, and can be placed within a conditional.

The Sybase "Transact-SQL Users Guide" (and other ASE reference documents) is a valuable resource which can be read on-line or downloaded as a PDF from the Sybase website. The documentation area is currently named "Infocenter". The document set is updated for each release.

Here is an extract from the above-mentioned guide about break (and continue)...

break and continue control the operation of the statements inside a while loop. break causes an exit from the while loop. Any statements that appear after the end keyword that marks the end of the loop are executed. continue causes the while loop to restart, skipping any statements after continue but inside the loop. break and continue are often activated by an if test.

The syntax for break...continue is:

while boolean expression
begin
    statement
    [statement]...
    break
    [statement]...
    continue
    [statement]...
end
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top