Session variables

A session variable is a named memory variable that you access through SQL statements. Session variables let you share data between SQL statements without the need for application logic to support this data transfer.

The Db2 for z/OS® supports the following types of session variables:

Built-in session variables
Built-in session variables are provided with the database manager. The value of a built-in session variable can be obtained by invoking the GETVARIABLE built-in function to retrieve the scalar value associated with the variable.

For more information about built-in session variables, see Built-in session variables.

User-defined session variables
User-defined session variables can be defined in connection and sign-on routines. A user-defined session variable is available to any active SQL statement that is running on the database manager on which the variable was defined. The value of a user-defined session variable is associated with a specific session and contains a value that is unique to that session. User-defined session variables let users extend the functionality of the database management system by adding their own or third-party vendor variable definitions.

Up to 10 user-defined session variables can be defined in the connection exit routine and the sign-on exit routine. For more information about defining user-defined session variables, see Session variables in connection and sign-on routines.

You can obtain the value of a user-defined or built-in session variable by invoking the GETVARIABLE function with the name of the session variable. For more information on retrieving the value of a session variable, see GETVARIABLE scalar function.