SQL LEN() Function
LEN() – The LEN() function used to returns the length of text field.
The syntax of LEN() is :
SELECT LEN(col_name) FROM Table_Name
Let’s understand LEN() function with an example :
We have SQL Table StudentMst with below column.
SELECT * FROM StudentMst
ID | Name | City | Pincode | Mobile |
---|---|---|---|---|
1 | Meera | Bombay | 380022 | 7874555555 |
2 | Rahul | Surat | 352200 | 7874444444 |
3 | Jayesh | Ahmedabad | 352200 | 7874333333 |
4 | Dhvanish | Bombay | 380022 | 7874111111 |
5 | Reena | Baroda | 352222 | 7874666666 |
6 | Veera | Baroda | 352222 | 7874121212 |
SELECT LEN(Name) AS Name,LEN(City) AS City FROM StudentMst
Name | City |
---|---|
5 | 6 |
5 | 5 |
6 | 9 |
8 | 6 |
5 | 6 |
5 | 6 |