DB2 function call Method

Source: Internet
Author: User
Tags db2 functions

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.