Overview
TheLENGTH()
function is used to find the length of a string, i.e., the number of characters in a given string. It accepts a string as a parameter. Syntax of the length function is illustrated below:
- If a null value is passed in the function, i.e.,
LENGTH(NULL)
, it will returnNULL
. - If the parameter is an empty string
LENGTH(")
, it will return 0. - If the parameter is a space character
LENGTH('')
, not empty or null, it will return 1 as it is not empty anymore.
Examples
#Case 1: Basic LENGTH()
function
The below example uses the LENGTH()
function to find out the length of a string text:
#Case 2: LENGTH()
function using columns
Let’s see how the LENGTH()
function works on the personal_details table containing the employee’s id, first_name, last_name, and gender of a retail store as columns.