SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Dynamic SQL
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
9-2
Statements for Dynamic SQL With Arguments
Statements for Dynamic SQL With Arguments
Some of the dynamic SQL statements commonly used in programs are:
These statements are described on subsequent pages in this section. For the complete
syntax of each statement, see the SQL/MX Reference Manual.
Input Parameters and Output Variables
An input parameter is a symbol in a dynamic SQL statement that serves as a
placeholder for a value substituted when the statement executes. Input parameters are
specified as question marks (?).
An input parameter can appear in an SQL expression wherever a constant can appear.
Using a parameter, you can prepare an SQL statement without the input values.
Specify the data type of the parameter explicitly by using the CAST function so that
NonStop SQL/MX correctly types the parameter. The input values are then provided
when the statement executes.
NonStop SQL/MX returns data to a program through output variables. Output variables
are user-specified areas in the program. Output variables typically contain columns
returned from a SELECT operation.
If you are using the form of the EXECUTE statement that provides a list of arguments
in the USING and INTO clauses, you must know the nature of the dynamic input
parameters and any SELECT list columns. The number of arguments and the data
types of arguments provided in the EXECUTE statement must match both the number
and the data types of parameters in the prepared statement.
If you do not know the number and data types of arguments, use the form of the
EXECUTE statement that uses descriptor areas. See Section 10, Dynamic SQL With
Descriptor Areas.
Floating-Point Variables
Depending on the setting for the CONTROL QUERY DEFAULT FLOATTYPE
statement, input and output will either be in IEEE FLOAT format or Tandem FLOAT
format. The default value is Tandem FLOAT format for dynamic SELECT statements
PREPARE Prepares (compiles) a dynamic SQL statement for
subsequent execution by an EXECUTE statement.
DEALLOCATE PREPARE Deallocates a prepared statement and returns the
system resources used by the statement and also
allows reuse of the statement name.
EXECUTE Executes a prepared dynamic SQL statement.
EXECUTE IMMEDIATE Prepares (compiles) and executes a dynamic SQL
statement in one step.