NonStop SQL/MP Reference Manual

Table Of Contents
NonStop SQL/MP Reference Manual142115
P-15
Examples—Parameters
If the target column has a numeric data type, SQL treats the parameter as
DECIMAL(n), where n is the number of digits in the parameter value.
If the target column has a character data type and the target column has the
UNKNOWN character set associated with it, SQL treats the parameter as CHAR(n),
where n is the number of bytes in the parameter value.
If the target column has a character data type and the target column has a character
set other than UNKNOWN associated with it, SQL treats the data type of the
parameter as
CHAR(n) CHARACTER SET character-set-name
where character-set-name is the character set specified in the parameter
value and n is the number of quoted characters in the parameter value. In this case,
the parameter value must be a string literal.
If you omit the TYPE AS clause from a parameter in a date-time or INTERVAL
expression, SQL assigns data types to the parameters according to the following
rules:
°
The data type is INTERVAL if the parameter name is followed by a range of
fields and start-field-precision is specified.
°
The data type is DATETIME if the parameter name is followed by a range of
fields and start-field-precision is not specified or if the expression
has any of the following forms:
parameter-name { + | - } interval-term
interval-expression + parameter-name
date-time-expression - parameter-name
°
The data type is NUMERIC if the expression takes either of the following
forms:
parameter-name { + | - } scalar-value
{ + | - } parameter-name
Examples—Parameters
In the following example, you can substitute different values for the ?DEPT1 and
?DEPT2 parameters each time you execute the statement:
SELECT AVG (SALARY) FROM PERSNL.EMPLOYEE
WHERE DEPTNUM BETWEEN ?DEPT1 AND ?DEPT2;
Then you can prepare the command with the name AVGSAL and execute it like
this:
EXECUTE AVGSAL USING ?DEPT1 = 2000, ?DEPT2 = 4000;