SQL/MX Programming Manual for C and COBOL (H06.10+, J06.03+)
Introduction
HP NonStop SQL/MX Programming Manual for C and COBOL—544617-003
1-5
Declaring and Using Static SQL Cursors
Examples
In these C examples, a semicolon (;) ends an embedded SQL statement. In a COBOL
program, the keyword END-EXEC ends an embedded SQL statement.
•
Single-row SELECT statement
EXEC SQL SELECT custname
INTO :hv_custname
FROM sales.customer
WHERE custnum = :hv_this_customer;
The result of the SELECT is placed into a host variable. The selection of the single
row is based on the value of the primary key (CUSTNUM column) as provided by
the host variable.
•
INSERT statement
EXEC SQL INSERT INTO persnl.job (jobcode, jobdesc)
VALUES (:hv_jobcode, :hv_jobdesc);
The values of the columns inserted into the JOB table are provided by host
variables.
•
Searched UPDATE statement
EXEC SQL UPDATE persnl.employee
SET salary = salary * :hv_inc
WHERE salary < :hv_min_salary;
The SALARY column of all employees below a minimum salary is multiplied by a
specified factor. The values of the minimum salary and the factor are provided by
host variables.
•
Searched DELETE statement
EXEC SQL DELETE FROM invent.partsupp
WHERE partnum BETWEEN :hv_first_num AND :hv_last_num;
The rows whose part numbers are between two specified numbers are deleted
from the PARTSUPP table. The values for the lower and upper part numbers are
provided by host variables.
See Section 5, Simple and Compound Statements.
Declaring and Using Static SQL Cursors
Because your 3GL program cannot handle unlimited sets of data, to retrieve data from
a set of rows into your application program and then process data from that set, you
must process the set one row at a time. You do this by using a cursor.
A cursor is like a pointer that traverses the set of rows in the result table of a SELECT
statement. You specify the SELECT statement when you declare the cursor. You
establish the result table of the SELECT when you open the cursor. You then fetch the
C










