LENGTH query

We can get length of the character present against each data can be found by using LENGTH command.
SELECT LENGTH('Welcome');
The output is 7

Student Table

Let us find out the length of name present in our student table.
SELECT id, name, length(name) FROM `student`
We will get a list of id , name and length like this
1 John Deo  8
2 Max Ruin 8
3 Arnold 6
We can also use length in numeric field like this
SELECT id, name, length(name),length(mark) FROM `student`
Now let us try to find some blank data using length query
SELECT id, name FROM `student` where length(mark) <=1
This will display records where Mark is single digit or not entered.

What is the difference between length and char_length ?

Length returns string measured in bytes, but char_length returns number of characters. All chars does not occupy single byte particularly Unicode where chars are encoded in two bytes. Here is an example.
SELECT LENGTH( _utf8 '' ) , CHAR_LENGTH( _utf8 '' )
Output is here
2,1

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


Google+

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer