Home » Technology » Howto

MySQL - How to select data by string length ?

Submitted by Vidhu on Apr 28 2013 Views: 4615 | Subscribe


How to select data by string length
MySQL - How to select data by string length ?

Functions : CHAR_LENGTH() ,BIT_LENGTH(), LENGTH()

CHAR_LENGTH() : Returns the length of the string measured in characters.

Examples:

select * from customerlist order by CHAR_LENGTH(name);

select NAME, CHAR_LENGTH(name) from customerlist ;

SELECT * FROM customerlist WHERE CHAR_LENGTH(name)>5 ;

BIT_LENGTH() : Returns the length of the string measured in bits.

Examples:

select * from customerlist order by BIT_LENGTH(name);

select NAME, BIT_LENGTH(name) from customerlist ;

SELECT * FROM customerlist WHERE BIT_LENGTH(name)>5 ;

LENGTH() : Returns the length of the string measured in bytes.

Examples:

select * from customerlist order by LENGTH(name);

select NAME, LENGTH(name) from customerlist ;

SELECT * FROM customerlist WHERE LENGTH(name)>5 ;


Tags: MySQL,mysql string length, char_length

Get email updates. Virus Removal Tips, News, How to, Threat Alerts.

Leave a comment!