The end of the DB2 char type is filled with spaces

Source: Internet
Author: User
Tags db2 db2 case

The name of the student who queried the surname "Liu" and whose full name is 2 characters:

SELECT Sname

From Student

WHERE Sname like ' Liu __ ';

Why is there no result? I changed the two lines to a% after the results come out, is it not in the DB2 inside the horizontal line does not represent any single character?



After the experiment found




DB2 Wildcard "_"


Only one byte can be matched. DB2 Case:


The char type, which is filled with spaces at the end of the DB2 char type.

If your sname is defined as char (8), then ' Liu xx ' actually holds ' Liu xx ' in the database, followed by 5 spaces.

So you use _ query when you need to write ' Liu _______ ', so that you can correctly match.

The end of the DB2 char type is filled with spaces.



Or you can change the idea of:

SELECT * from T_basicpersonalcustomers WHERE personalname like ' Wang% English ' and length (personalname) = 6

This will match up. Wang Faying Wang to English and other data



Match time format can be used 2014-07-25 15:56:00 The following sentence can be found in the data but not with 2014/07/25 15:56:00 this form but the DB2 may be stored in the form of 2014/07/25 15:56:00 this kind of.

select * from T_basicpersonalcustomers WHERE updatetime between ' 2014-07-25 15:56:00 ' and ' 2014-07-25 19:11:37 '

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.