SQL Programming Manual for Pascal
Host Variables and Parameters
HP NonStop SQL Programming Manual for Pascal—528614-001
2-13
Using Parameters in Loops
Using Parameters in Loops
Parameters are often used when a dynamic SQL statement is executed repeatedly
with different input values.
Example
The user of the program described in the following example can enter any SQL
statement—the program does not have compile-time information about the statement.
A DEFINE named =PARTS is in effect for the PARTS table.
The scenario includes these steps:
1. A user enters this SQL statement from a terminal:
UPDATE =PARTS SET PRICE = ?P
2. The program copies the statement into the host variable INTEXT.
3. The program uses the PREPARE and DESCRIBE INPUT statements to put a
description of the parameter in the SQLDA structure and to put the name of the
parameter in the names buffer.
The SQLDA structure is named IN_SQLDA; the names buffer is named
I_NAMESBUF; the prepared statement is named S1.
EXEC SQL PREPARE S1 FROM :INTEXT;
...
EXEC SQL DESCRIBE INPUT S1 INTO :IN_SQLDA
NAMES INTO :I_NAMESBUF;
4. The program enters a loop to prompt the user to supply values for successive
execution of the statement:
{ Beginning of loop }
{ Prompt the user for a value using the parameter }
{ name from the names buffer }
...
{ Store value in an input buffer pointed to by IN_SQLDA}
{ Execute the statement using each successive value: }
EXEC SQL EXECUTE S1 USING DESCRIPTOR :IN_SQLDA;
{ End of loop }
Using Indicator Parameters
An indicator parameter has a function similar to that of an indicator host variable. A
program uses an indicator parameter to show that a null value was entered for a