SQL/MP Programming Manual for COBOL

Data Retrieval and Modification
HP NonStop SQL/MP Programming Manual for COBOL529758-003
4-4
Single-Row SELECT Statement
The program has not yet opened the cursor.
The program has opened the cursor, but the OPEN CURSOR statement did not
require any input host variables, and the first FETCH statement has not yet been
executed.
However, if the problem occurs on a FETCH statement, the SQL executor closes the
cursor and returns error -8204. The program must then close and reopen the cursor
before executing a subsequent FETCH statement. The program might need to abort
the transaction and restart the cursor operation from its beginning.
Single-Row SELECT Statement
A single-row SELECT statement retrieves a single row of data from one or more tables
or views and places the column values into corresponding host variables.
To select a set of rows one row at a time by using a cursor, see Using SQL Cursors on
page 4-12.
To execute a SELECT statement, a process started by the program must have read
access to all tables, protection views, and the underlying tables of shorthand views
used in the statement. For information about process access, see Required
Access Authority on page 7-1.
Do not use an asterisk (*) in a SELECT statement in a COBOL program. A SELECT
statement with an asterisk always assigns columns in the result table from the current
definition of the referenced tables or views. If columns have been added to a table, the
retrieved data values might not be in the expected order.
SQL/MP returns these values to SQLCODE after a SELECT statement.
For more information about SQLCODE, see Section 9, Error and Status Reporting.
Using a Column Value to Select Data
This SELECT statement returns a row containing a customers name and address
based on a unique column value (a nonkey value). Each customer is identified by a
unique number so that only one customer satisfies the query. This example uses a
WHERE clause to specify that the CUSTOMER.CUSTNAME column contains a unique
value equal to the host variable named FIND-THIS-CUSTOMER. Example 4-1 sets
FIND-THIS-CUSTOMER to customer number 5635 by using an assignment statement,
but in a typical application, a user would enter the customer number.
SQLCODE Value Description
0 The SELECT statement was successful.
100 No rows qualified for the SELECT statement specification.
< 0 An error occurred; SQLCODE
contains the error number.
> 0 (not 100) A warning occurred; SQLCODE contains the warning number.