The CREATE VARIABLE statement creates a new variable of the specified data type. If you specify initial-value, the variable is set to that value. If you do not specify an initial-value, the variable contains the NULL value until a different value is assigned by the SET statement.
Specifying the OR REPLACE clause drops the named variable if it already exists and replaces its definition. You can use the
OR REPLACE clause as an alternative to the VAREXISTS function in SQL scripts. See VAREXISTS function [Miscellaneous].
A variable can be used in a SQL expression anywhere a column name is allowed. Name resolution is performed as follows:
Match any aliases specified in the query's SELECT list.
Match column names for any referenced tables.
Assume the name is a variable.
Variables belong to the current connection, and persist until you disconnect from the database or when you use the DROP VARIABLE
statement. Variables are not visible to other connections. Variables are not affected by COMMIT or ROLLBACK statements.
Variables are useful for creating large text or binary objects for INSERT or UPDATE statements from embedded SQL programs.