Summary of special characters in SQL fuzzy query

Source: Internet
Author: User
When the where statement contains the like condition, if the parameter needs to match special characters such as % and _, it must be processed; otherwise, it will be processed as a wildcard. Sqlserver: two solutions are available: Replace [with [], % with [%], and _ with [_]. (This solution is recommended) 2. Replace \ with \, [with \ [, and % with \ %, and _ \_;

Add the escape '\' after each field that requires like query '\'.
Note: Only parameters and SQL statements can be modified through oracle in the sqlserver2005 test. Replace \ with \, % with \ %, and _ with \ _. Then, add escape CHR (92 using nchar_cs) to each field that requires like query ), the SQL statement format is as follows: Select * from a where name like '% \ %' escape CHR (92 using nchar_cs) or ADDR like '% \ _ %' escape CHR (92 using nchar_cs); the length of escape CHR (92 using nchar_cs) must be written in Oracle 9i, 10 Gb in Oracle can be abbreviated as escape '\'
Note: similar to Oracle in the case that Oracle9i and 10G pass MySQL, you also need to use the escape statement. However, after testing, the escape '\' cannot be used, so the escape '/' is used '/'
Replace/with //, % with/%, _ with/_, and \ /\; add the escape '/' after each field that requires like query '/'.
Note: escape cannot be used for access tests in MySQL 5.5, but similar to sqlserver, you only need to replace [with [], % with [%], replace _.
Note: access2003 passed the test

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.