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.


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;


Search Keys

  • sql len function
  • sql length
  • sql server len
  • sql string length
  • length sql
  • length sql server
  • sql server length
  • oracle string length
  • sql datalength
  • sql strlen
  • select length sql
  • sql text length
  • datalength

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
5 The Complete Guide to Oracle 85 2008 Administration Bala Murugan
6 SQL Server 2012 Black Book 105 2013 Database Balan
7 How to Write Accurate SQL Code 75 2009 Administration Vidyavathi
8 Mastering Oracle SQL 150 2006 Database Ranjani Mai
9 The Complete Guide to SQL Server 165 2014 Programming Siva Kumar
10 SQL Visual Quickstart 160 2013 Database Bala Murugan
11 Microsoft SQL Server 2008 168.27 2007 Optimization Dharan
12 Sql Server Interview Questions 185 2008 Optimization Hanumanthan

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
5 The Complete Guide to Oracle 28 85 2
6 SQL Server 2012 Black Book 26 105 3
7 How to Write Accurate SQL Code 30 75 2
8 Mastering Oracle SQL 20 150 3
9 The Complete Guide to SQL Server 32 165 3
10 SQL Visual Quickstart 21 160 3
11 Microsoft SQL Server 2008 25 168.27 6
12 Sql Server Interview Questions 30 185 3

Search Keys

  • sql field length
  • sql character length
  • sql server string length function
  • sql length command
  • char length
  • function len
  • length function in sql
  • sql count characters
  • count characters sql
  • how to count rows in sql
  • sql count string
  • sql character functions
  • sql string functions with examples