MySQL learn three about escaping

Source: Internet
Author: User
Tags db2

The DB2 like predicate query statement supports the use of percent sign (%), underscore (_), does not support square brackets ([]) (note: It treats square brackets as actual values rather than wildcards), and when we need to query for the percent sign (%), underscore (_) as the actual value in the like query condition, You need to use escape characters to tell DB2 to treat them as actual values rather than as escape characters. However, the escape character is not defined in DB2 (backslash \ is not an escape character in DB2), so it needs to be defined using the Escape keyword like '%!% ' escape '! '.

It is worth noting that the processing of single quotes is a bit different from the processing of a percent sign (%), an underscore (_), which can only be escaped using single quotes for single quotes, for example: Like ' A% ', which matches the string "a" that begins with the string percent sign (%) Escape: SELECT * From table where col1 like '%/%% ' escape '/' this statement means to find a record that contains a percent percent (%) character in col1. Where escape defines the escape character "/" underscore (_) Escape: SELECT * FROM table where col1 like '%!_% ' escape '! ' The meaning of this statement is to find a record that contains the underscore (_) character in the col1. Where escape defines the escape character "!" escape of single quotation marks: SELECT * from table where col1 like '% '% ' This statement means: Find records containing single quote characters in col1

MySQL learn three about escaping

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.