Precautions for using special characters in mysql

Source: Internet
Author: User


Precautions for using special characters in mysql 1. Directly spell it into SQL: www.2cto.com ● if it is "= ", the code for converting the escape character to '\ To \ is as follows: SQL = SQL. replace ("'", "'' "); SQL = SQL. replace ("\", "\"); ● if it is "like ", escape characters from '\ % _' to ''\ To \ (note that 8 characters are required, Chinese characters) the code for converting % to \ % _ is as follows: SQL = SQL. replace ("'", "'' "); SQL = SQL. replace ("\", "\"); SQL = SQL. replace ("%", "\ %"); SQL = SQL. replace ("_","\\_"); 2. SQL preprocessing ● only when "like" is used, escape \ To \ % to \ % _ to \ _ SQL = SQL. rep Explain ("\", "\"); SQL = SQL. replace ("%", "\ %"); SQL = SQL. replace ("_", "\ _"); Note: because MySQL uses the C implicit method (for example, "\ n") in the string "), you must repeat any "\" in your LIKE string. For example, in order to find "\ n", specify it as "\ n", in order to find "\", specify it as "\\\\" (The backslash is stripped once during java syntax analysis, and the other is when the Database pattern matching is completed, the reverse skew of a single line is matched ).
 

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.