• We just launched and are currently in beta. Join us as we build and grow the community.

SQL LEN() Function

SRCLegacy

Skill Tree Master
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
118
Likes
177
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
The LEN function is useful to count the number of characters in a column you specified as the parameter. LEN is short for length. The LEN function returns the number of characters including spaces or any character within that column.

You can use SQL Alias to name the result of the LEN function.

SQL LEN() Syntax

SELECT

LEN(

column_name)

FROM

TABLE

Consider the following table for this exercise.

Users

Firstname

Lastname

Salary

DeptID

John

Smith

1000

1

Mathew

Simon

3000

1

Bill

Steve

2200

1

Amanda

Rogers

1800

2

Steve

Hills

2800

2

Steve

jobs

2400

2

bill

cosby

700

3

Example # 1

SELECT

LEN(

Firstname)

AS

Firstname_Length FROM

users

Result of the Query

Firstname_Length

5

5

5

6

5

4

5

You can also add other column if you wish.

Example # 2

SELECT

Firstname,

Lastname,

LEN(

Firstname)

AS

Firstname_Length FROM

users

Firstname

Lastname

Firstname_Length

John

Smith

5

Mathew

Simon

5

Bill

Steve

5

Amanda

Rogers

6

Steve

Hills

5

Steve

jobs

4

bill

cosby

5

 

452,292

323,348

323,357

Top