Special registers

A special register is a storage area that is defined for an application process by the database manager and is used to store information that can be referenced in SQL statements. A reference to a special register is a reference to a value provided by the current server. If the value is a string, its CCSID is a default CCSID of the current server. The special registers can be referenced as follows:

Read syntax diagramSkip visual syntax diagram>>-+-+-CURRENT DATE------+------+------------------------------><
   | |              (1)  |      |
   | '-CURRENT_DATE------'      |
   +---CURRENT DEBUG MODE-------+
   +---CURRENT DEGREE-----------+
   +-+-CURRENT PATH----------+--+
   | +-CURRENT FUNCTION PATH-+  |
   | |              (1)      |  |
   | '-CURRENT_PATH----------'  |
   +-+-CURRENT SCHEMA-+---------+
   | '-CURRENT_SCHEMA-'         |
   +-+-CURRENT SERVER-+---------+
   | '-CURRENT_SERVER-'         |
   +-+-CURRENT TIME------+------+
   | |              (1)  |      |
   | '-CURRENT_TIME------'      |
   +-+-CURRENT TIMESTAMP------+-+
   | |                   (1)  | |
   | '-CURRENT_TIMESTAMP------' |
   +-+-CURRENT TIMEZONE-+-------+
   | '-CURRENT_TIMEZONE-'       |
   +-+-SESSION_USER-+-----------+
   | '-USER---------'           |
   '---SYSTEM_USER--------------'
 
Notes:
  1. The SQL 2003 Core standard uses the form with the underscore.

CURRENT DATE

The CURRENT DATE special register specifies a date that is based on a reading of the time-of-day clock when the SQL statement is executed at the current server. If this special register is used more than once within a single SQL statement, or used with CURRENT TIME, CURRENT TIMESTAMP, or the CURDATE, CURTIME, or NOW scalar functions within a single statement; all values are based on a single clock reading.26

Example

Using the PROJECT table, set the project end date (PRENDATE) of the MA2111 project (PROJNO) to the current date.

   UPDATE PROJECT
     SET PRENDATE = CURRENT DATE
     WHERE PROJNO = 'MA2111'

CURRENT DEBUG MODE

The CURRENT DEBUG MODE special register specifies whether SQL or Java procedures should be created or altered so they can be debugged by the Unified Debugger. Any explicit specification of the DEBUG MODE or the DBGVIEW option in the SET OPTION statement on the CREATE PROCEDURE or ALTER PROCEDURE statement overrides the value in the CURRENT DEBUG MODE special register. CURRENT DEBUG MODE affects static and dynamic SQL statements. The data type of the register is VARCHAR(8). The valid values include:

DISALLOW
Procedures will be created so they cannot be debugged by the Unified Debugger. When the DEBUG MODE attribute of a procedure is DISALLOW, the procedure can be subsequently altered to change the DEBUG MODE attribute.
ALLOW
Procedures will be created so they can be debugged by the Unified Debugger. When the DEBUG MODE attribute of a procedure is DISALLOW, the procedure can be subsequently altered to change the DEBUG MODE attribute.
DISABLE
Procedures will be created so they cannot be debugged by the Unified Debugger. When the DEBUG MODE attribute of a procedure is DISABLE, the procedure cannot be subsequently altered to change the DEBUG MODE attribute.

The value can be changed by invoking the SET CURRENT DEBUG MODE statement. For details about this statement, see SET CURRENT DEBUG MODE.

The initial value of CURRENT DEBUG MODE is DISALLOW.

Example

The following statement prevents subsequent creates or alters of SQL or Java procedures from being debuggable:

   SET CURRENT DEBUG MODE = DISALLOW

CURRENT DEGREE

The CURRENT DEGREE special register specifies the degree of I/O or Symmetric MultiProcessing (SMP) parallelism for the execution of queries, index creates, index rebuilds, index maintenance, and reorganizes. CURRENT DEGREE affects static and dynamic SQL statements. The data type of the register is CHAR(5). The valid values include:

1
No parallel processing is allowed.
2 through 32767
Specifies the degree of parallelism that will be used.
ANY
Specifies that the database manager can choose to use any number of tasks for either I/O or SMP parallel processing.

Use of parallel processing and the number of tasks used is determined based on the number of processors available in the system, this job's share of the amount of active memory available in the pool in which the job is run, and whether the expected elapsed time for the operation is limited by CPU processing or I/O resources. The database manager chooses an implementation that minimizes elapsed time based on the job's share of the memory in the pool.

NONE
No parallel processing is allowed.
MAX
The database manager can choose to use any number of tasks for either I/O or SMP parallel processing. MAX is similar to ANY except the database manager assumes that all active memory in the pool can be used.
IO
Any number of tasks can be used when the database manager chooses to use I/O parallel processing for queries. SMP is not allowed.

The value can be changed by invoking the SET CURRENT DEGREE statement. For details about this statement, see SET CURRENT DEGREE.

The initial value of CURRENT DEGREE is determined by the current degree in effect from the CHGQRYA CL command, PARALLEL_DEGREE parameter in the current query options file (QAQQINI), or the QQRYDEGREE system value.

Example

The following statement inhibits parallelism:

   SET CURRENT DEGREE  = '1'

CURRENT PATH

The CURRENT PATH special register specifies the SQL path used to resolve unqualified distinct type names, function names, and procedure names in dynamically prepared SQL statements. It is also used to resolve unqualified procedure names that are specified as variables in SQL CALL statements (CALL variable). The data type is VARCHAR(3483).

The CURRENT PATH special register contains the value of the SQL path which is a list of one or more schema names, where each schema name is enclosed in delimiters and separated from the following schema by a comma. The delimiters and commas are included in the length of the special register. The maximum number of schema names in the path is 268.

For information on when the SQL path is used to resolve unqualified names in both dynamic and static SQL statements and the effect of its value, see Unqualified function, procedure, specific, and distinct type names.

The initial value of the CURRENT PATH special register in an activation group is established by the first SQL statement that is executed.

The value of the special register can be changed by executing the SET PATH statement. For details about this statement, see SET PATH. For portability across the platforms, it is recommended that a SET PATH statement be issued at the beginning of an application.

Example

Set the special register so that schema SMITH is searched before schemas QSYS and QSYS2 (SYSTEM PATH).

   SET CURRENT PATH SMITH, SYSTEM PATH

CURRENT SCHEMA

The CURRENT SCHEMA special register specifies a VARCHAR(128) value that identifies the schema name used to qualify unqualified database object references where applicable in dynamically prepared SQL statements.27 CURRENT SCHEMA is not used to qualify names in programs where the DYNDFTCOL has been specified. If DYNDFTCOL is specified in a program, its schema name is used instead of the CURRENT SCHEMA schema name.

The initial value of CURRENT SCHEMA is the authorization ID of the current session user.

The DFTRDBCOL keyword controls the schema name used to qualify unqualified database object references where applicable for static SQL statements.

Example

Set the schema for object qualification to 'D123'.

   SET CURRENT SCHEMA = 'D123'

CURRENT SERVER

The CURRENT SERVER special register specifies a VARCHAR(18) value that identifies the current application server.

CURRENT SERVER can be changed by the CONNECT (Type 1), CONNECT (Type 2), or SET CONNECTION statements, but only under certain conditions. See the description in CONNECT (Type 1), CONNECT (Type 2), and SET CONNECTION.

CURRENT SERVER cannot be specified unless the local relational database is named by adding the entry to the relational database directory using the ADDRDBDIRE or WRKRDBDIRE command.

Example

Set the host variable APPL_SERVE (VARCHAR(18)) to the name of the current server.

   SELECT CURRENT SERVER
     INTO :APPL_SERVE
     FROM SYSDUMMY1

CURRENT TIME

The CURRENT TIME special register specifies a time that is based on a reading of the time-of-day clock when the SQL statement is executed at the current server. If this special register is used more than once within a single SQL statement, or used with CURRENT DATE, CURRENT TIMESTAMP, or the CURDATE, CURTIME, or NOW scalar functions within a single statement; all values are based on a single clock reading.28

Example

Using the CL_SCHED table, select all the classes (CLASS_CODE) that start (STARTING) later today. Today's classes have a value of 3 in the DAY column.

   SELECT CLASS_CODE FROM CL_SCHED
     WHERE STARTING > CURRENT TIME  AND DAY = 3

CURRENT TIMESTAMP

The CURRENT TIMESTAMP special register specifies a timestamp that is based on a reading of the time-of-day clock when the SQL statement is executed at the current server. If this special register is used more than once within a single SQL statement, or used with CURRENT DATE, CURRENT TIME, or the CURDATE, CURTIME, or NOW scalar functions within a single statement; all values are based on a single clock reading.29

Example

Insert a row into the IN_TRAY sample table. The value of the RECEIVED column should be a timestamp that indicates when the row was inserted. The values for the other three columns come from the host variables SRC (CHAR(8)), SUB (CHAR(64)), and TXT (VARCHAR(200)).

   INSERT INTO IN_TRAY
     VALUES (CURRENT TIMESTAMP, :SRC, :SUB, :TXT)

CURRENT TIMEZONE

The CURRENT TIMEZONE special register specifies the difference between UTC 30 and local time at the current server. The difference is represented by a time duration (a decimal number in which the first two digits are the number of hours, the next two digits are the number of minutes, and the last two digits are the number of seconds). The number of hours is between -24 and 24 exclusive. Subtracting CURRENT TIMEZONE from a local time converts that local time to UTC.

Example

Using the IN_TRAY table, select all the rows from the table and adjust the value to UTC.

   SELECT RECEIVED - CURRENT TIMEZONE, SOURCE,
         SUBJECT, NOTE_TEXT FROM IN_TRAY

SESSION_USER

The SESSION_USER special register specifies the run-time authorization ID at the current server. The data type of the special register is VARCHAR(128).

The initial value of SESSION_USER for a new connection is the same as the value of the SYSTEM_USER special register. Its value can be changed by invoking the SET SESSION AUTHORIZATION statement.

Example

Select all notes from the IN_TRAY table that the user placed there himself.

   SELECT * FROM IN_TRAY
     WHERE SOURCE = SESSION_USER

SYSTEM_USER

The SYSTEM_USER special register specifies the authorization ID that connected to the current server. The data type of the special register is VARCHAR(128).

Example

Select all notes from the IN_TRAY table that the user placed there himself.

   SELECT * FROM IN_TRAY
     WHERE SOURCE = SYSTEM_USER

USER

The USER special register specifies the run-time authorization ID at the current server. The data type of the special register is VARCHAR(18).

The initial value of USER for a new connection is the same as the value of the SYSTEM_USER special register. Its value can be changed by invoking the SET SESSION AUTHORIZATION statement.

Example

Select all notes from the IN_TRAY table that the user placed there himself.

   SELECT * FROM IN_TRAY
     WHERE SOURCE = USER

26.
LOCALDATE can be specified as a synonym for CURRENT_DATE.
27.
For compatibility with DB2 UDB for z/OS, the special register CURRENT SQLID is treated as a synonym for CURRENT SCHEMA.
28.
LOCALTIME and LOCALTIME(0) can be specified as a synonyms for CURRENT_TIME.
29.
LOCALTIMESTAMP and LOCALTIMESTAMP(6) can be specified as a synonym for CURRENT_TIMESTAMP.
30.
Coordinated Universal Time, formerly known as GMT.



[ Top of Page | Previous Page | Next Page | Contents | Index ]