If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > LIKE with ESCAPE option

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-04, 15:43
cheechq cheechq is offline
Registered User
 
Join Date: Feb 2004
Posts: 1
Question LIKE with ESCAPE option

I have a case where I would always like to use the ESCAPE option with a LIKE clause. (Droping ESCAPE from my query is not an option.) I cannot figure out how to escape the escape character defined in the LIKE clause. I'm using mySQL 4.0.14-max

I have the following table and data.

CREATE TABLE skill_category (
id BIGINT NOT NULL,
name VARCHAR(64) NOT NULL,
create_user VARCHAR(32) NOT NULL,
create_date DATETIME NOT NULL,
update_user VARCHAR(32) NOT NULL,
update_date DATETIME NOT NULL,
CONSTRAINT pk_skill_category PRIMARY KEY(id),
CONSTRAINT uk_skill_category01 UNIQUE (name)
) TYPE=InnoDB;

mysql> select * from skill_category;
+----+-------------+-------------+---------------------+-------------+---------------------+
| id | name | create_user | create_date | update_user | update_date |
+----+-------------+-------------+---------------------+-------------+---------------------+
| 1 | Skil^l | SYSTEM | 2004-02-06 14:17:12 | SYSTEM | 2004-02-06 14:17:12 |
| 2 | skill cat 1 | default | 2004-02-06 14:17:12 | default | 2004-02-06 14:17:12 |
| 3 | skill cat 2 | default | 2004-02-06 14:17:12 | default | 2004-02-06 14:17:12 |
| 4 | skill cat 3 | default | 2004-02-06 14:17:12 | default | 2004-02-06 14:17:12 |
+----+-------------+-------------+---------------------+-------------+---------------------+
4 rows in set (0.00 sec)

mysql> select * from skill_category where name like 'Skil^^l' escape '^';
Empty set (0.00 sec)

How should I correctly escape the defined escape character('^')?

Also I find it interesting that the query below returns 1.

mysql> select 'Skil^l' LIKE 'Skil^^l' ESCAPE '^';
+------------------------------------+
| 'Skil^l' LIKE 'Skil^^l' ESCAPE '^' |
+------------------------------------+
| 1 |
+------------------------------------+
1 row in set (0.00 sec)

I appreciate any help.
-Frank
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On