A cursor operation consists of these SQL statements, which you must invoke in the following order:
CA OPS/MVS executes one FETCH statement for each row to be fetched, until it has processed all of the rows in your table or you end the cursor operation.
Example: Syntax for Cursor Operations
Because the statements that control cursor operations function in sets, the examples that follow show groups of statements you invoke together to update or delete rows one at a time.
Note: You may specify the text ADDRESS SQL on each statement, as shown in Example 2. However, since these statements should follow one another in the order shown, it is necessary to specify the text ADDRESS SQL only on the DECLARE CURSOR statement, as shown in the following example.
ADDRESS SQL "DECLARE cursorname CURSOR FOR selectstatement" "OPEN cursorname" "FETCH cursorname INTO hostvarlist" "UPDATE tablename SET colname = string | :hostvar | NULL [, colname = string | :hostvar | NULL] WHERE CURRENT OF cursorname" "CLOSE cursorname"
For descriptions of the operands, see the text following Example 2.
ADDRESS SQL "DECLARE cursorname CURSOR FOR selectstatement" ADDRESS SQL "OPEN cursorname" ADDRESS SQL "FETCH cursorname INTO hostvarlist" ADDRESS SQL "DELETE FROM tablename WHERE CURRENT OF cursorname" ADDRESS SQL "CLOSE cursorname"
This is the 1- to 18-character name of the cursor (pointer) that provides a common reference point for a set of related SQL cursor operation statements.
This is the text of a SELECT statement to execute when you invoke the OPEN statement. This SELECT statement should use the syntax described in SELECT Statement in this chapter.
Used on the FETCH statement, the hostvarlist variable identifies a set of host variable names to store the selected column values. The order in which you specify REXX stem names should correspond to the order in which column names are specified on the DECLARE CURSOR statement.
This is the table containing the rows to be updated by the UPDATE statement or deleted with the DELETE FROM statement.
Copyright © 2014 CA.
All rights reserved.
|
|