DB2 function calling is one of our most common operations. The following describes the implementation methods of DB2 function calling for your reference. We hope this will help you.
If a user defines a function in DB2 that involves a specific table operation, it cannot be called like a system function. In this case, we can use the following statement to query the return value of the function:
Values unction_name (input_paramter_list)
For example:
Values online ('user1', date ('2017-5-5 '));
The preceding statement creates a virtual table and displays the returned values. If we want to reference the return value in the function, we can query it using the following statement:
Select * from (values online ('user1', date ('2017-5-5 ') as;
Note that the entire values statement is referenced when it is used as a nested query. Therefore, you should include it and assign it to alias ). This statement can be used in database operation solutions such as jdbc or hibernate to query the return values of the online (username, time) function.
VALUES statement
First look at the following statement:
Insert into log (uid, operation, logtime)
Values
(4,1, CURRENT timestamp ),
(4,1, CURRENT timestamp ),
(4,0, CURRENT timestamp );
This is a common insert statement. The statement uses the values statement to obtain a virtual table with the same structure as the log, containing the above three records, and inserts it into the log table.
Let's look at the following statement:
Select * from
(
Values
(4,1, CURRENT timestamp ),
(4,1, CURRENT timestamp ),
(4,0, CURRENT timestamp)
) As log (uid, operation, logtime );
This statement is defined from the virtual table with the alias log as above) to query all records. You can also add a field alias after the alias, so that the returned table will identify the field with an auto-incrementing positive integer from left to right.
All the preceding statements use the values statement. The values statement obtains the returned value and creates a virtual table. We can use values to implement the following functions ):
0. Create a list of constants and constants, variables, and return values as virtual tables.
For example, select * from (values 1, 2) as;
Or: select * from (values 1, 2) as a (OK) where OK = 1;
This is its own function. You can obtain many application methods through this feature;
1. Write select or insert statements as above );
2. Reference of the function return value. See the beginning of this article: Call DB2 functions. The values statement applies to any function, and some special functions can only return values through this statement.
Connect SQL SERVER to the DB2 database
DB2 index creation principles
Implementation of DB2 circular Query
Rollback of A DB2 partitioned Database
Three types of DB2 database backup solutions