RDB/VMS SQL FETCH — VMS RDB_4.2
FETCH ---+
+-------+
+-+------------------->---------------++-cursor-name ++
++------------->-------------+ FROM ++-parameter---+|
+> fetch-orientation-clause + |
+--------------<--------------------------------------+
+-+---------------->------------------+-> ;
+>INTO -+-> parameter ---+----------+
| +--- , <---------+ |
+>USING DESCRIPTOR descriptor-name -+
Additional information available:
More Informationfetch orientation clausecursor name
More Information
The FETCH statement advances a cursor to the next row of its result table and retrieves the values from that row. You can use the FETCH statement in interactive SQL, in precompiled programs, or as part of an SQL module language procedure. When used in precompiled programs or as part of an SQL module language procedure, FETCH assigns the values from the row to parameters. In interactive SQL, FETCH displays the value of the row on the terminal screen. When used with a list cursor, the FETCH statement positions the cursor on a specified place within a list and retrieves a portion of the list. When you fetch a list cursor in interactive SQL, you cannot use the USING clause. With list cursors, you can only use the USING clause in a dynamic FETCH statement. When you use the FETCH statement with a table cursor, you cannot use the INTO and USING clauses in interactive SQL. You must use either the INTO or USING clause in FETCH statements that are embedded in precompiled programs or are part of an SQL module language procedure.
fetch orientation clause
fetch-orientation-clause =
---+-> NEXT --------------------------------+->
+-> PRIOR --------------------------------+
+-> FIRST --------------------------------+
+-> LAST ---------------------------------+
+-> RELATIVE -- simple-value-expression --+
+-> ABSOLUTE -- simple-value-expression --+
Additional information available:
More informationsimple value expression
More information
The fetch-orientation clause specifies the specific segment of
the list cursor to fetch. These options are only available if
you have specified the SCROLL option in the DECLARE CURSOR
statement. The choices are:
o Next
Fetches the next segment of the list cursor. This is the
default.
o Prior
Fetches the segment immediately before the current segment
of the list cursor.
o First
Fetches the first segment of the list cursor.
o Last
Fetches the last segment of the list cursor.
o Relative simple-value-expression
Fetches the segment of the list cursor indicated by the
value expression. For example, relative -4 would fetch the
segment 4 segments prior to the current segment.
o Absolute simple-value-expression
Fetches the segment of the list cursor indicated by the
value expression. For example, absolute 4 would fetch the
fourth segment of the list cursor.
simple value expression
The simple-value-expression must be either a positive or negative integer or a numeric module language or host language parameter.
cursor name
The name of the cursor from which you want to retrieve a row.
INTO
The INTO clause specifies a list of parameters to receive the values SQL retrieves from the cursor. The number of parameters in the list must be the same as the number of values in the row of the cursor. (If any of the parameters are host structures, SQL counts the number of variables in that structure when it compares the number of parameters in the INTO clause with the number of values in the row.) The data types of parameters must be compatible with the values of the corresponding column of the cursor row.
USING
Specifies the name of a descriptor that corresponds to an SQL Descriptor Area (SQLDA). In a precompiled program, if you used the INCLUDE statement to insert the SQLDA into your program, the descriptor name is simply SQLDA. Programs that call SQL module language procedures must explicitly declare an SQLDA descriptor and can give it any name. An SQLDA is a collection of variables used only in dynamic SQL. In a FETCH statement, the SQLDA points to a number of parameters SQL uses to receive the values of the row. The number of variables must match the number of values in the row. The data types of parameters must be compatible with the values of the corresponding column of the cursor row.