FOR

Execute statements for each row of a result set.

for_loop.png

 

Usage

Procedural.

Description

The result set defined by the query expression is iterated and for each row found the list of procedural-sql-statements in the for body is executed. All columns of the result set are available as variables within the for body. This means that all items in the select list must have a unique name. If a for-name is given, this can be used to qualify variable references within the for body.

The query expression can be a call to a result set procedure in which case the names in result-set-clause is used as variable names.

For a list of procedural-sql-statements, see Procedural SQL Statements.

Restrictions

If labels are specified at both the beginning and the end of the FOR statement, they must be the same.

If a label is specified at the end it must also be specified at the beginning.

The for-name may not be the same as the name of a label for any compound statement within the scope of the for statement.

The body of a FOR statement is atomic which means that it cannot contain a COMMIT, ROLLBACK, or START statement.

Notes

A FOR statement may be terminated by a LEAVE statement using label.

Examples

FOR SELECT code, country, currency_code FROM countries DO

   RETURN (code, country, currency_code);

END FOR;

 

FOR st AS CALL mimer_store_web.view_basket(session_number) DO

    IF  st.title = 'American splendour' THEN

       ...

   ELSE

       ...

   END IF;

END FOR;

 

For more information, see the Mimer SQL Programmer's Manual, Iterating through a result set - FOR loop.

Standard Compliance

Standard

Compliance

Comments

SQL-2016

Features outside core

Feature P002, “Computational completeness”.

 

Mimer SQL extension

The support for CALL is a Mimer SQL extension.