Deckard
Deckard

Reputation: 1433

mysql Length() for different languages returns different size

select 

length('abcdefg') english,
length('가나다라마바사') korean

from dual

This returns below.

english korean
7       21

Is there any function returning the count of character not character bytes?

I mean what I need is

english korean
7       7

Upvotes: 5

Views: 253

Answers (2)

Pekka
Pekka

Reputation: 449385

See the manual:

Returns the length of the string str, measured in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing five 2-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.

CHAR_LENGTH() will do what you want.

Upvotes: 2

Nimrod007
Nimrod007

Reputation: 9913

use :

CHAR_LENGTH()

(the number of characters)

reference :

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length

Upvotes: 3

Related Questions