In SQL, LEN function is used to determine the length of the specified string.
In SQL, A string is a data type used to store data that can contain combination of numbers, letters, whitespaces and symbols. In simple term, String is a word or a sequence of characters.
A substring is a consecutive sequence of characters or a portion of a string.
LEN(string)
• Specify the 'string' in single quotes ( ' ' ) or 'column' whose length you want to determine.
1. Let's assume we have a table named "[Employees]".
2. Let's assume you want to determine the length of each employees name from [Employees] table.
3. Run below SQL statement :
SELECT LEN(Employee_Name) FROM [Employees];
4. In above statement, LEN function determines the length of each employee's name from the Employee_Name column.
It returns 4 for employees 'Mike', 'John' and 'Alex' due to their total letter count of 4, While for the employees 'Dolly' and 'Casey' it returns 5 due to their total letter count of 5.
Using this function in a select statement won't modify the [Employees] table directly, but it will only be reflected in the select statement's output.
The LEN function in SQL returns the length of a string.
To check the length in SQL, you can use the LEN function.
In SQL, LENGTH is used in some databases like MySQL, while LEN is used in others like SQL Server; both perform similar tasks.
The LEN function in data calculates the length of a string or the number of characters in a field.