SQL Programming Manual for Pascal
Introduction
HP NonStop SQL Programming Manual for Pascal—528614-001
1-5
Compiling and Executing a Program
The program in Figure 1-2 accesses the PARTS table, which exists on a different
subvolume. When this program runs, it prompts an operator for information to build the
INSERT statement. The operator enters the following information in the INTEXT
variable to specify the location of the PARTS table and other values needed to
construct the INSERT statement:
INSERT INTO $VOL5.SALES.PARTS
(PARTNUM, PRICE, PARTDESC)
VALUES (4120, 60000.00, "V8 DISK OPTION")
The program builds the INSERT statement from the information in INTEXT and moves
the statement to the host variable OPERATION. The program has declared
OPERATION as a host variable, so that it is available to both Pascal and SQL
statements. The program then uses EXECUTE IMMEDIATE to compile and execute
the INSERT statement in OPERATION.
For more information, see Section 7, Using Dynamic SQL and Appendix C, Examples
of Dynamic NonStop SQL Programs.
Compiling and Executing a Program
Compiling and executing a Pascal program that contains embedded SQL statements is
similar to the procedure you use to compile and execute a Pascal program that does
not contain embedded SQL statements. You must perform only one extra step: compile
the Pascal object program by using the SQL compiler. Figure 1-3 on page 1-6 shows
the steps you follow to compile and execute your program.
Figure 1-2. Dynamic SQL Statement in a Pascal Program
{ Pascal variable declarations }
EXEC SQL BEGIN DECLARE SECTION;
VAR OPERATION : FSTRING (200);
EXEC SQL END DECLARE SECTION;
. . .
PROCEDURE INSERT_DATA;
BEGIN
. . .
READLN (INTEXT);
OPERATION := INTEXT;
EXEC SQL EXECUTE IMMEDIATE :OPERATION;
END;
VST0102.vsd