Here is all about special registers in DB2. Special Register is a pre-defined definition in DB2 Server. These you can use readily in SQL queries. So, you will get an answer to complex scenarios.
ON THIS PAGE

DB2 Special Registers
These DB2 special registers are frequently used in real-time DB2 programs to obtain relevant information. The list includes Current Date, Current Degree, Current Schema, Current Path, and Current Server.
How to prompt ‘current Date’
The ‘CURRENT DATE’ is a special register that prompts the current date when used.
SELECT AVG(YEAR(CURRENT DATE - BIRTHDATE))
FROM DSN8A10.EMP
How to use ‘CURRENT DEGREE‘
It sets whether to use parallelism or not.
SET CURRENT DEGREE = '1'
VALUES CURRENT DEGREE INTO :DEG_USED
The CURRENT DEGREE = 1, states not to use Parallelism. If you say any, then it will use parallel processing to run your Query.
How to Use “CURRENT PATH”
The special register purpose is to select the current Schema, which the given SQL query to use. Usually, we will give an SQL query. Suppose, if you do not mention it, then it will use the path you mentioned in the ‘SET PATH’ command.
The SET PATH command is useful when you run ‘Stored Procedures‘ and ‘Functions‘ without specifying the schema.
SET PATH = SMITH, SYSTEM PATH
VALUES CURRENT PATH INTO :MY_PATH
How to Use ‘CURRENT SCHEMA’
When you use ‘CURRENT SCHEMA’ in the SQL query, it takes the already set schema.
SET SCHEMA = 'D123'
VALUES CURRENT SCHEMA INTO :MY_SCHEMA
How to use ‘CURRENT SERVER’
The “CURRENT SERVER” gets the server name is used.
EXEC SQL SET :CS = CURRENT SERVER
VALUES CURRENT SERVER INTO :APPL_SERVE
Conclusion
These special registers in DB2 provide valuable information and can be used in various scenarios to enhance the flexibility and functionality of your SQL queries.
Related Posts







You must be logged in to post a comment.