SQL LEN() | LENGTH() Function


The SQL LEN() function returns the length of the value of a given input string or in a table field.

The SQL LEN() function count all types of data including Alphabet, number and symbols.

The SQL LEN() function is supports or work with character and numeric based columns.

It can be used in any valid SQL SELECT statement as well in SQL where clause.

You can also search these topics using sql string length, length sql server, sql server length, oracle string length, select length sql.

SQL LEN() | LENGTH() Syntax

The basic syntax is to get number of characters available in the string or table column.

For Microsoft Sql Server | Access


// For input string or text

SELECT LEN(string or text);

// For specific table column value

SELECT LEN(column_name1) FROM table_name;

For MySql


// For input string or text

SELECT LENGTH(string or text);

// For specific table column value

SELECT LENGTH(column_name1) FROM table_name;


SQL LEN() | LENGTH() Example - Using Expression Or Formula

The following SQL SELECT statement returns the integer value of a given input string.

For Microsoft Sql Server | Access


SELECT LEN('Hello') AS 'Total Characters';

For MySql


SELECT LENGTH('Hello') AS 'Total Characters';

The result of above query is:

Total Characters
5

SQL LEN() Function More Example

Input Value Result
Len('Hi!') 3
Len('Simmanchith.com') 15
Len('What is database?') 17
Len('123...789') 9

Sample Database Table - Books

BookId BookName BookPrice RelYear DomainName AuthorName
1 Programming With MySQL 123.45 2009 Security Ramanathan
2 Troubleshooting Oracle 178.69 2015 Optimization Vinoth Kumar
3 Teach Yourself SQL 195 2012 Optimization Bala Murugan
4 SQL Puzzles & Answers 110 2012 Optimization Harish Karthik

SQL LEN() | LENGTH() Example

The following SQL statement selects the "BookName" and "BookPrice" column and find the length of the values from the "Books" table:

For Microsoft Sql Server | Access


SELECT BookID, 
BookName, LEN(BookName) As 'Length Of BookName', 
BookPrice, LEN(BookPrice) As 'Length Of BookPrice' 
FROM Books;

For MySql


SELECT BookID, 
BookName, LENGTH(BookName) As 'Length Of BookName', 
BookPrice, LENGTH(BookPrice) As 'Length Of BookPrice' 
FROM Books;

The result of above query is:

BookID BookName Length Of BookName BookPrice Length Of BookPrice
1 Programming With MySQL 22 123.45 6
2 Troubleshooting Oracle 22 178.69 6
3 Teach Yourself SQL 18 195 3
4 SQL Puzzles & Answers 21 110 3
You can also search these topics using sql character length, sql server string length function, sql length command, length function in sql, sql count characters, count characters sql, how to count rows in sql, sql character functions, sql string functions with examples.