MainframeSupports
tip week 7/2015:

Right from the beginning DB2 was born with some built-in variables called special registers. Through the years as more functionality was added to DB2 the number of special registers was also increased. In DB2 11 there are a total of 37 special registers. In DB2 version 8 IBM decided for some odd reason to introduce a new kind of built-in variables called built-in session variables and made eleven of these variables. In version 9 the number of these variables was increased to 33 and has remained the same in DB2 10 and 11.

As you probably already know the way you retrieve the value of a special register is quite straight forward. You simply type <special register name> in the place where you need the variable in your SQL. This is not the case with a built-in session variable. Instead you need to write GETVARIABLE('<built-in session variable name>'). An example:

SELECT CURRENT TIMESTAMP
     , GETVARIABLE('SYSIBM.PACKAGE_NAME')
     , GETVARIABLE('SYSIBM.VERSION')
FROM SYSIBM.SYSDUMMY1

This SQL statement will retrieve a timestamp, the name of the program executing your SQL statement and the version of the DB2 executing your statement. Please be aware of the peculiar detail of putting the name of the variable in apostrophes (or quotes). Please browse the list of built-in session variables to see whether there are some variables on the list you have been missing as special registers.

Previous tip in english        Forrige danske tip        Tip list