mcbalaji
mcbalaji

Reputation: 183

Unicode character in Select Query using LIKE in mysql

I am getting wrong output if i use Unicode tamil characters in LIKE MySQL query

Select * from tbl_name where colName LIKE 'ச%';

In the above Query I am getting records starting with சொ,சு,சே,சூ,சா,சி. what I need is the letter starting only.

colHWord சகதி சக்தி சகாயம் சகுனம் சங்கம் சங்கிரகம் சங்கு சடை சத்தியம் சந்தடி சந்தர்ப்பம் சந்திரகலை சந்தேகம் சபதம் சப்பு சபை சம்பிரமம் சம்புடம் சமம் சம்மதம் சமயம் சமன் சரி சரிவு சலனன் சறுக்கு சனி சாக்கு சாட்சி சாணம் சாத்து சாதனம் சாதனை சாதி சாந்து சாபம் சாமர்த்தியம் சாய் சாய்வு சாயை சார் சார்பு சாவகாசம் சாறு சிக்கனம் சிகரம் சிங்காரம் சித்திரம் சித்திரி சிதறு சிதைவு சிந்து சிலை சிவப்பு சிறகு சிறப்பு சிறப்புவிதி சிற்றுண்டி சிறை சின்னம் சினேகம் சினை சீவு சுடு சுமை சுரண்டு சுரணை சுருக்கம் சுருக்கு சுருங்கு சுருட்டு சுவர் சுவை சுழி சுற்றம் சுற்று சூரியன் சூழ்ச்சி சூழ்வோர் செதுக்கு செம்மறி செய்தி செருக்கு செருகு செல்வம் செலவு செழிப்பு செறிவு சேர் சேவகம் சேவை சேறு சேனை சொரி சொல் சோபானம் சோம்பு சோறு சௌக்கியம்

Upvotes: 1

Views: 474

Answers (3)

Neechalkaran
Neechalkaran

Reputation: 313

சொ,சு,சே,சூ,சா,சி are the combination of two Unicode character so query must be specific to pull ச. Below is the one of the way to omit other letters

SELECT * FROM tbl_name WHERE colName LIKE 'ச%' AND colName NOT LIKE 'சா%' AND colName NOT LIKE 'சி%' AND colName NOT LIKE 'சு%' AND colName NOT LIKE 'சொ%' AND colName NOT LIKE 'சே%' AND colName NOT LIKE 'சூ%';

There should some other way using REGEXP, But I'm unable to find it.

Upvotes: 0

Zelldon
Zelldon

Reputation: 5516

Normaly LIKE should work with 'ச%'.

But you can try to use the unicode as hex value OR you could also use the REGEXP operator.

Adjust your SQL statement like this

SELECT * FROM tbl_name WHERE colName  REGEXP '^ச.*';

Upvotes: 0

Vikas Rana
Vikas Rana

Reputation: 1999

You can use LIKE BINARY in place of %, something like this

Select * from tbl_name where colName LIKE BINARY 'ச';

Upvotes: 1

Related Questions