Updated on 2023-10-31 GMT+08:00

Cursor Loop

The use of cursors in WHILE and LOOP statements is called a cursor loop. Generally, OPEN, FETCH, and CLOSE statements are needed in cursor loop. The following describes a loop that is applicable to a static cursor loop without executing the four steps of a static cursor.

Syntax

Figure 1 shows the syntax diagram for the FOR AS loop.

Figure 1 FOR_AS_loop::=

Precautions

  • The UPDATE operation for the queried table is not allowed in the loop statement.
  • The variable loop_name is automatically defined and is valid only in this loop. The type and value of loop_name are the same as those of the query result of select_statement.
  • The %FOUND, %NOTFOUND, and %ROWCOUNT attributes access the same internal variable in GaussDB(DWS). Transactions and anonymous blocks cannot be accessed by multiple cursors at the same time.

Examples