In DB2 or any other database, you can find some special registers. Special Register means, it is a pre-defined definition in DB2 Server.
The Special Registers you can use readily in SQL queries. So that you will get an answer to complex scenarios.
The best example is ‘CURRENT DATE”. The Current Date is a special register. So that when you use this you will get a Date.
The Best Examples on Special Registers that are present in DB2
How to Use Current Date in SQL Query
SELECT AVG(YEAR(CURRENT DATE - BIRTHDATE))
FROM DSN8A10.EMP;
How to use CURRENT DEGREE in SQL Query
SET CURRENT DEGREE = '1';
VALUES CURRENT DEGREE INTO :DEG_USED
The CURRENT DEGREE = 1, specifies that do not use Parallelism. If you say any, then it will use parallel processing to run your Query.
How to Use “CURRENT PATH” in SQL Query
The special register purpose is to select the current Schema, which the given SQL query to use. Usually, we will give in an SQL query. Suppose, if you do not mention, then it will use the path you mentioned in the ‘SET PATH’ command.
SET PATH Command useful when you run ‘Stored Procedures’ and ‘Functions‘ without giving the Schema.
SET PATH = SMITH, SYSTEM PATH;
VALUES CURRENT PATH INTO :MY_PATH
How to Use ‘CURRENT SCHEMA’ in SQL Query
This is useful for all SQL Queries. Just you can use ‘CURRENT SCHEMA’ in the SQL query. So, the Schema, which you already sets will use.
SET SCHEMA = 'D123'
VALUES CURRENT SCHEMA INTO :MY_SCHEMA
How to use ‘CURRENT SERVER’ in SQL Query
You can use “CURRENT SERVER” in the SQL query to get the server name is used.
EXEC SQL SET :CS = CURRENT SERVER;
VALUES CURRENT SERVER INTO :APPL_SERVE
Related Posts