WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL LEN() Function


LEN () function

The

LEN () function returns the length of the value in a text field.

SQL LEN () syntax

  SELECT LEN   (  column_name < /span> )   FROM table_name  ;  

LENGTH () in MySQL:

SELECT LENGTH(column_name) FROM table_name;


Demo database

In this tutorial, we will use the welookups sample database.

Here is the data from the "Websites" table:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/  | 1     | USA     |
| 2  | zomato          | https://www.zomato.com/ | 13    | IN      |
| 3  | indiamart      | http://www.indiamart.com/  | 4689  | IN      |
| 4  | Yahoo          | http://Yahoo.com/       | 20    | IN      |
| 5  | Facebook     | https://www.facebook.com/| 3     | USA     |
| 7  | stackoverflow | http://stackoverflow.com/|   0 | IND     |
+----+---------------+---------------------------+-------+---------+


SQL LEN () instance

The following SQL statement selects the length of the values in the "name" and "url" columns from the "Websites" table:

Example

SELECT name, LENGTH (url) as LengthOfURL
FROM Websites;

The result of executing the above SQL is as follows: