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( )

Syntax

The syntax for the Length function is as follows:

Length (str)

The length of the string str is returned.

Examples

We use the following table for our examples.

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 © 2017   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact