SQL Programming Manual for TAL
Introduction
HP NonStop SQL Programming Manual for TAL—527887-001
1-5
Using Dynamic SQL Operations
For other examples of static SQL programming, see Section B, Examples of Static
NonStop SQL Programs.
Using Dynamic SQL Operations
A dynamic SQL operation enables a TAL program to construct, compile, and execute
an SQL statement at run time. With a static SQL operation, you code the SQL
statement to be executed in the source file; however, with a dynamic SQL operation,
you code only the host variable that will contain the SQL statement.
A dynamic SQL operation requires some input, usually from a user at a terminal, to
construct the final statement. The SQL statement is constructed from the user’s input,
compiled by the SQL compiler, and then executed using an EXECUTE or EXECUTE
IMMEDIATE statement.
Figure 1-1. Static SQL Statements in a TAL Program
...
! TAL variable declarations:
EXEC SQL BEGIN DECLARE SECTION;
! SQL host variable declarations
STRUCT .in^parts^rec;
BEGIN
INT in^partnum;
FIXED(2) in^price;
STRING in^partdesc[0:17];
END;
EXEC SQL END DECLARE SECTION;
! Procedure Code:
in^parts^rec.in^partnum := 4120;
in^parts^rec.in^price := 60000.00F;
! Blank fill in^partdesc:
in^parts^rec.in^partdesc ':='
[ $OCCURS(in^parts^rec.in^partdesc) * [" "] ];
in^parts^rec.in^partdesc ':=' "V8 DISK OPTION";
EXEC SQL INSERT INTO SALES.PARTS
( PARTNUM, PRICE, PARTDESC)
VALUES (:in^parts^rec.in^partnum,
:in^parts^rec.in^price,
:in^parts^rec.in^partdesc);
...
VST0101.vsd