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
192
April 18, 2020 08:37PM
Re: LIKE not working as expected
59
April 23, 2020 07:13PM


Sorry, only registered users may post in this forum.

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.