SQL > SQL String Functions > Length Function

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

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

The syntax for the Length function is as follows:

Length (str)
The above finds the length of the string str.

Let's take a look at some examples. Assume we have the following table:

Table Geography

Region_NameStore_Name
EastBoston
EastNew York
WestLos Angeles
WestSan Diego

Example 1

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

Result:

Length (Store_Name)
11

Example 2

SELECT Region_Name, Length (Region_Name)
FROM Geography;

Result:

Region_NameLength (Region_Name)
East4
East4
West4
West4

Next: SQL Replace




Copyright © 2014 1keydata.com   All Rights Reserved.   Privacy Policy