Types of global variables
There are three different ways to classify global variables: by the ownership of the variable, by the scope of the value, and by the method used to maintain the value.
Ownership of the variable
A global variable
can be classified based on whether the variable is owned by the database
manager, or if the variable is user-defined:
- The database manager creates built-in global variables.
Built-in global variables are registered to the database manager in
the system catalog. Built-in global variables belong to the following
schema:
- SYSIBM
- SYSIBMADM
- SYSHADOOP
- A user creates a user-defined global variable by using an SQL DDL statement. User-defined global variables are registered to the database manager in the system catalog. A user-defined schema global variable is created by using the CREATE VARIABLE SQL statement. A user-defined module global variable is created using the ADD VARIABLE or PUBLISH VARIABLE option of the ALTER MODULE SQL statement.
Scope of the value
A global variable can
be classified as either session or database based on the scope of
the value:
- The value of a session global variable is uniquely associated with each session that uses this particular global variable. Session global variables are either built-in global variables or user-defined global variables.
- The value of a database global variable is a single value that remains the same for all sessions that use this particular global variable. Database global variables are always built-in global variables.
Method by which the value is maintained
A
global variable can be classified based on how the variable is maintained:
- A constant global variable has a fixed value that is instantiated based on evaluation of the CONSTANT clause when the global variable is first referenced in the session or the database, depending on the scope of the global variable. This type of global variable is created by using the CONSTANT clause in the CREATE VARIABLE statement. A value cannot be assigned to the global variable using an SQL statement. Constant global variables are read-only global variables.
- A maintained-by-system global variable has a value that is set by the database manager. A value cannot be assigned using an SQL statement. Only built-in global variables can be defined as maintained-by-system global variables, and most built-in global variables are defined as maintained-by-system global variables. Maintained-by-system global variables are read-only global variables.
- A maintained-by-user global variable can be assigned a value using an SQL statement; however, this assignment requires WRITE privilege on the global variable. This type of global variable is the default for user-defined global variables that are defined without using a CONSTANT clause. Built-in global variables can also be defined so values can be assigned using an SQL statement.