The <replaceable>expression</replaceable> must return a value that
The <replaceable>expression</replaceable> must return a value that
is a boolean or can be casted into a boolean.
is of type <type>boolean</type> or can be casted to a <type>boolean</type>.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -636,60 +637,60 @@ Loops
...
@@ -636,60 +637,60 @@ Loops
<listitem>
<listitem>
<para>
<para>
There are multiple types of loops.
There are multiple types of loops.
<programlisting>
<synopsis>
[<<label>>]
<optional><<label>></optional>
LOOP
LOOP
<replaceable>statements</replaceable>
<replaceable>statements</replaceable>
END LOOP;
END LOOP;
</programlisting>
</synopsis>
An unconditional loop that must be terminated explicitly
An unconditional loop that must be terminated explicitly
by an EXIT statement. The optional label can be used by
by an EXIT statement. The optional label can be used by
EXIT statements of nested loops to specify which level of
EXIT statements of nested loops to specify which level of
nesting should be terminated.
nesting should be terminated.
<programlisting>
<synopsis>
[<<label>>]
<optional><<label>></optional>
WHILE <replaceable>expression</replaceable> LOOP
WHILE <replaceable>expression</replaceable> LOOP
<replaceable>statements</replaceable>
<replaceable>statements</replaceable>
END LOOP;
END LOOP;
</programlisting>
</synopsis>
A conditional loop that is executed as long as the evaluation
A conditional loop that is executed as long as the evaluation
of <replaceable>expression</replaceable> is true.
of <replaceable>expression</replaceable> is true.
<programlisting>
<synopsis>
[<<label>>]
<optional><<label>></optional>
FOR <replaceable>name</replaceable> IN [ REVERSE ] <replaceable>expression</replaceable> .. <replaceable>expression</replaceable> LOOP
FOR <replaceable>name</replaceable> IN <optional> REVERSE </optional> <replaceable>expression</replaceable> .. <replaceable>expression</replaceable> LOOP
<replaceable>statements</replaceable>
<replaceable>statements</replaceable>
END LOOP;
END LOOP;
</programlisting>
</synopsis>
A loop that iterates over a range of integer values. The variable
A loop that iterates over a range of integer values. The variable
<replaceable>name</replaceable> is automatically created as type
<replaceable>name</replaceable> is automatically created as type
integer and exists only inside the loop. The two expressions giving
integer and exists only inside the loop. The two expressions giving
the lower and upper bound of the range are evaluated only when entering
the lower and upper bound of the range are evaluated only when entering
the loop. The iteration step is always 1.
the loop. The iteration step is always 1.
<programlisting>
<synopsis>
[<<label>>]
<optional><<label>></optional>
FOR <replaceable>record | row</replaceable> IN <replaceable>select_clause</replaceable> LOOP
FOR <replaceable>record | row</replaceable> IN <replaceable>select_clause</replaceable> LOOP
<replaceable>statements</replaceable>
<replaceable>statements</replaceable>
END LOOP;
END LOOP;
</programlisting>
</synopsis>
The record or row is assigned all the rows resulting from the select
The record or row is assigned all the rows resulting from the select
clause and the loop body is executed for each row. If the loop is
clause and the loop body is executed for each row. If the loop is
terminated with an EXIT statement, the last assigned row is still
terminated with an EXIT statement, the last assigned row is still
accessible after the loop.
accessible after the loop.
<programlisting>
<synopsis>
[<<label>>]
<optional><<label>></optional>
FOR <replaceable>record | row</replaceable> IN EXECUTE <replaceable>text_expression</replaceable> LOOP
FOR <replaceable>record | row</replaceable> IN EXECUTE <replaceable>text_expression</replaceable> LOOP
<replaceable>statements</replaceable>
<replaceable>statements</replaceable>
END LOOP;
END LOOP;
</programlisting>
</synopsis>
This is like the previous form, except that the source SELECT
This is like the previous form, except that the source SELECT
statement is specified as a string expression, which is evaluated
statement is specified as a string expression, which is evaluated
and re-planned on each entry to the FOR loop. This allows the
and re-planned on each entry to the FOR loop. This allows the
programmer to choose the speed of a pre-planned query or the
programmer to choose the speed of a pre-planned query or the
flexibility of a dynamic query, just as with a plain EXECUTE
flexibility of a dynamic query, just as with a plain EXECUTE
statement.
statement.
<programlisting>
<synopsis>
EXIT [ <replaceable>label</replaceable> ] [ WHEN <replaceable>expression</replaceable> ];
EXIT <optional> <replaceable>label</replaceable> </optional> <optional> WHEN <replaceable>expression</replaceable> </optional>;