SQL LENGTH, SQL LEN

SQL LENGTH or SQL LEN Function is used to get the length of a string. Different databases have different writtings:

SQL Server LEN
Oracle LENGTH
MySQL LENGTH

SQL LENGTH Syntax

LENGTH(str)

Or:

LEN(str)

SQL LENGTH Example

Table: Employees

EmployeeId FirstName LastName
1 Mazojys Fxoj
2 Jozzh Lnanyo
3 Syllauu Dfaafk
4 Gec Srlkrt
5 Jssmee Bdnaa

Get the FirstName’s length of each employee:

SELECT EmployeeId, LEN(FirstName) AS LengthOfFirstName
FROM Employees

The result will look like:

EmployeeId LengthOfFirstName
1 7
2 5
3 7
4 3
5 6

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>