SQL > SQL String Functions > Length Function

The Length function in SQL is used to get the length of a string. This function has a different name for different databases:

  • MySQL: LENGTH( )
  • Oracle: LENGTH( )
  • SQL Server: LEN( )


The syntax for the Length function is as follows:

Length (str)

The length of the string str is returned.


We use the following table for our examples.

Table Geography

 Region_Name  Store_Name 
 East  Boston 
 East  New York 
 West  Los Angeles 
 West  San Diego 

Example 1

SELECT Length (Store_Name)
FROM Geography
WHERE Store_Name = 'Los Angeles';


Length (Store_Name)

Example 2

SELECT Region_Name, Length (Region_Name)
FROM Geography;


Region_Name Length (Region_Name)
East 4
East 4
West 4
West 4

Next: SQL Replace

This page was last updated on June 19, 2023.

Copyright © 2024   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact