Saturday, October 8, 2011

MySQL strlen

What is the string length function in MySQL?

There are two MySQL functions for string length:

1. LENGTH(str) returns the length of the string in bytes.

Usage example:
select length(username) from users;

2. CHAR_LENGTH(str) returns the character count of the string. The difference occurs when multibyte (such as UTF-8) characters are used.

For example, length('aä') will return 3, while char_length('aä') will return 2.

No comments:

Post a Comment