Built-in global variables

Built-in global variables are provided with the database manager and are used in SQL statements to retrieve scalar values associated with the variables.

As an example, the ROUTINE_TYPE global variable is referenced in an SQL statement to retrieve the current routine type.

For most built-in global variables, the authorization ID of any statement that retrieves the value of the global variable is required to have the READ privilege on the global variable or DATAACCESS authority. However, there are exceptions where an authorization ID with other database authorities also has access to the global variable. Exceptions to the authorization required to retrieve the value of a global variable are specified within the descriptions of the built-in global variables.

In a non-restrictive database, the READ privilege is granted to PUBLIC for most built-in global variables at creation time. Exceptions to granting this privilege are specified within the descriptions of the built-in global variables.

Examples

  • To access the global variable CLIENT_HOST, run the following query:
    VALUES SYSIBM.CLIENT_HOST
    This query returns the host name of the current client:
    1         
    ----------
    hotellnx93
    
    An alternative way to call the global variable is to use it in a SELECT statement:
    SELECT C1, C2 
      FROM T1
      WHERE C3 = CLIENT_HOST
  • For read/write global variables, set the value with the SET variable statement:
    SET NLS_STRING_UNITS = 'CODEUNITS32'