SQL statements using basic DML types in MySQL, "and" are default string label symbols. In reality, however, the following situations often occur:
One: Query situation
SELECT book_id from PD WHERE isbn= ' 123456789 ' and Book_name= ' "China" and "cloud-dwelling community";
In this case, the book_name corresponding string is not problematic and the SQL statement has no syntax problems. But look at one of the following statements:
SQL, insert into yourtable (F1,F2) VALUES (M, ' abc ')
SELECT book_id from PD WHERE isbn= ' 123456789 ' and book_name= ' let ' S go! cloud-dwelling communities ';
Report exception: You have a error in your SQL syntax;
Here, you might say, you put the two single quotes from the periphery of the ' let ' go! cloud-dwelling community ' into double quotes. But the reality is often based on Murphy's law towards the worst. In many cases, we don't know whether the incoming, deleted, modified, and searched strings contain "," or both, so it is not easy to encounter single quotes replaced with double quotes, and double quotes are replaced with single quotes. This requires the use of SQL escape characters.
Two: Insert situation
String data is enclosed in single quotes, if the inserted data contains single quotes that need to be processed, you can replace single quotes with two single quotes, and two single quotes in SQL for a single quote character, such as
Insert into yourtable (F1,F2) VALUES (+, ' ab ' ' C ') represents inserting
New record F2 field AB ' C
Use function Replace to achieve this function: replace (YOURSTR, "'", "" ")