Purpose
Assigns a value to a local variable or parameter in a stored procedure.
Invocation
Executable.
Stored procedures only.
Syntax
SET assignment_target = assignment_source ;
where:
- assignment_target
- The name of the variable or parameter to be assigned a value.
- assignment_source
- The value to be assigned to assignment_source.
ANSI Compliance
SET is ANSI/ISO SQL:2011-compliant.
Authorization
None.
Rules
- All valid expressions except those containing subqueries are permitted in a SET statement assignment source.
- Both assignment target and assignment source must be specified.
- Assignment target is always on the left hand side (LHS) of the SET expression.
- Assignment source is always on the right hand side (RHS) of the SET expression.
- The data type of the assignment source must be compatible with the data type specified for the assignment target. Teradata Database performs implicit conversions for DateTime data types when the source data type differs from the target data type. For more information, see “Data Type Conversions” in Teradata Vantage™ - Data Types and Literals, B035-1143.
FOR this component of a SET assignment … | Valid Constructs Are... | Invalid Constructs Are... |
---|---|---|
assignment target |
|
|
assignment source | a literal or an expression containing one of the following:
|
|
Example: Using the SET Statement to Assign Values
The following example illustrates a valid use of the SET statement to assign values to variables and parameters.
SET hNoAccts = hNoAccts + 1; SET hErrorText = 'SQLSTATE: '||sqlstate|| ', SQLCODE: '||sqlcode||', ACTIVITY_COUNT: ' ||activity_count;