SQL_FETCH_NEXT_ROW¶
Applies to: ORAFlex SQLFlex MYSQLFlex PGFlex DB2Flex
This command is used to fetch the next row returned by the associated SQL statement. The SQL statement is created from the SQL_SET_STMT and executed with the SQL_EXECUTE_STMT. This command can be used in two ways. If the results are to be attached to variables, then no file needs to be specified, just the variables for each column in the row. If the results are to be inserted into the record buffer directly, then the file must be specified. From there, a SQL_BINDCOLUMNS_STMT can be used to bind the fetched row to the specific fields in the file. Note that the columns are fecthed in the order that the SQL statement generates them, so the variables must follow the same order. The two constants, “found” and “finderr” are set depending on whether the next row was found.
Syntax
SQL_FETCH_NEXT_ROW [of {file}] into {variable}
Parameter |
Description |
---|---|
file |
The name or number of the file |
variable |
The variable that the next column in the fetched row will be put into (can be multiple) |
Usage
SQL_FETCH_NEXT_ROW of Customer
SQL_FETCH_NEXT_ROW into sRecnum sID
Example
String sID sRecnum
SQL_SET_STMT to "SELECT * FROM CUSTOMER ID"
SQL_APPEND_STMT to " BY NAME DESC"
SQL_PREPARE_STMT
SQL_EXECUTE_STMT
While (found)
SQL_FETCH_NEXT_ROW into sRecnum sID
If (found) Begin
Showln sID
End
Loop
SQL_CANCEL_QUERY_STMT
Open Customer
SQL_SET_STMT of Customer to "SELECT * FROM CUSTOMER WHERE STATUS = 'Active'"
SQL_PREPARE_STMT of Customer
SQL_BINDCOLUMNS_STMT of Customer to DF_BIND_ALL_COLUMNS
SQL_EXECUTE_STMT of Customer
While (Found)
SQL_FETCH_NEXT_ROW of Customer
Showln Customer.ID
Showln Customer.FirstName
Showln Customer.LastName
Loop
SQL_CANCEL_QUERY_STMT