SQL Programming Manual for Pascal

NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for Pascal528614-001
3-15
Examples
Examples
This INSERT statement, you can substitute different values for the three parameters
each time you execute the statement.
INSERT INTO $VOL5.SALES.PARTS (PARTNUM, PRICE, PARTDESC)
VALUES ( ?P1, ?P2, ? )
The INSERT statement shown is contained in a host variable. You can also declare
host variables that will contain the parameter values.
The following example executes the INSERT statement. The statement is text in the
host variable DYNAMIC_INSERT_STATEMENT.
EXEC SQL BEGIN DECLARE SECTION;
TYPE
PARTS_TYPE : RECORD
IN_PARTNUM : INT16;
IN_PRICE : INT32;
IN_PARTDESC : FSTRING (18);
END;
VAR IN_PARTS_REC : PARTS_TYPE;
DYNAMIC_INSERT_STATEMENT : FSTRING (180);
EXEC SQL END DECLARE SECTION;
Prepare the statement with the name OPERATION. Then move the values you want to
substitute for the parameters to the host variables. Finally, execute the statement using
the EXECUTE statement.
EXEC SQL
PREPARE OPERATION FROM :DYNAMIC_INSERT_STATEMENT;
{ Get values for the parameters and move them to }
{ host variables: }
IN_PARTS_REC.IN_PARTNUM := 4120;
IN_PARTS_REC.IN_PRICE := 6000000;
IN_PARTS_REC.IN_PARTDESC := 'V8 DISK OPTION';
EXEC SQL
EXECUTE OPERATION USING
:IN_PARTS_REC.IN_PARTNUM,
SETSCALE(:IN_PARTS_REC.IN_PRICE, 2),
:IN_PARTS_REC.IN_PARTDESC;