MySQL Forums
Forum List  »  InnoDB

Re: LIKE not working as expected
Posted by: Robert Simpson
Date: April 23, 2020 07:13PM

Well, besides simply changing the names of the table and columns and the values inserted, you actually made two significant changes to my example. Using your names and values, the LIKE (not equals) still fails to produce any rows.

In case you liked those names and data values better than the ones in my example, try this version:

mysql> set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected (0.00 sec)

mysql> select version(), @@sql_mode;
+-----------+--------------------------------------------+
| version() | @@sql_mode                                 |
+-----------+--------------------------------------------+
| 5.1.73    | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+-----------+--------------------------------------------+
1 row in set (0.00 sec)

mysql> drop table if exists data;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> create table data ( stringvalue varchar(32)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Query OK, 0 rows affected (0.01 sec)

mysql> insert into data set stringvalue='Thor\'s Hammer';
Query OK, 1 row affected (0.00 sec)

mysql> insert into data set stringvalue='Thor\\''s Hammer';
Query OK, 1 row affected (0.00 sec)

mysql> select * from data;
+----------------+
| stringvalue    |
+----------------+
| Thor's Hammer  |
| Thor\'s Hammer |
+----------------+
2 rows in set (0.00 sec)

mysql> select * from data WHERE stringValue like '%\\%' escape '\\';
Empty set (0.01 sec)

mysql> select * from data WHERE stringValue like '%\\\\%' escape '\\';
Empty set (0.00 sec)

You can keep adding more backslash escapes, but that doesn't help.

Options: ReplyQuote


Subject
Views
Written By
Posted
814
April 18, 2020 08:37PM
382
April 18, 2020 09:14PM
371
April 19, 2020 10:38AM
Re: LIKE not working as expected
425
April 23, 2020 07:13PM
363
April 27, 2020 08:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.