Experiences in using like in DB2 Databases

Source: Internet
Author: User

This article will introduce some experiences of like in DB2, with examples for your reference, and hope to help you.

The use of like in DB2 is restricted. It cannot be followed by a variable or field. Currently, many variables are like '% test %'. Therefore, in a function or stored procedure, you cannot use a form parameter to form a dynamic condition for like.

If you want to search a field for a string in a function or stored procedure, you can use locate. The usage of locate is as follows:

Locate (arg1, arg2, <pos>): searches for the location where arg1 first appeared in arg2. If you specify pos, you can find the location where arg1 first appeared at the pos of arg2. The third parameter is optional)

The following is an example of using this method:

Create function gdzj. GETNOPASS
(Itemname varchar (100 ),
Reporttype integer,
RESULTID INTEGER
)
RETURNS INTEGER
Specific gdzj. SQL091102183311900
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
STATIC DISPATCH
CALLED ON NULL INPUT
EXTERNAL ACTION
INHERIT SPECIAL REGISTERS
Begin atomic
-- Return Value 0: This check item does not exist. 1: check items are available, but all items are qualified. 2: check items exist, but one is unqualified. If one fails, the system determines that it is unqualified)
DECLARE IResult INTEGER;
DECLARE ICount INTEGER;
Set IResult = 0;
-- REPORTTYPE: 1: external unit, 0: Non-External Unit
If REPORTTYPE = 1 then
Set ICount = (
Select count (1) from DETECT_END_INFO where
CHECK_OUT_UNIT_INFO_ID = RESULTID and locate (ITEMNAME, PROJECT_NAME)> 0
End;
 

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.