CodeBlanks Logo Icon CodeBlanks

LENGTH

Find the length of text.

LENGTH

LENGTH returns the number of characters in a text. It is used to filter by text length in conditions.

SELECT name, LENGTH(name) AS uzun FROM customers;

This query puts the character count next to each name.

name, LENGTH(name) AS uzun is selected from customers.

LENGTH — details

Some databases use LEN; the ANSI standard is LENGTH. Spaces are counted; trim first to ignore them.

Practice LENGTH

Select from customers those whose name is longer than 5 characters.

Starter code

query.sql
-- long names
SELECT name
FROM customers
WHERE

Sample solution

query.sql
SELECT name
FROM customers
WHERE LENGTH(name) > 5

Expected output

name
Ayşe
Ahmet

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Text length

Question
SELECT name, ____(name) FROM customers;
Answer
SELECT name, LENGTH(name) FROM customers;

Explanation: LENGTH returns the number of characters in the text.

2 What does LENGTH return?

  • The number of rows
  • The number of bytes
  • The number of words
  • The number of characters Correct answer

Explanation: LENGTH returns the character count.

3 LENGTH: match the terms

Term Meaning
LENGTH length
UPPER uppercase
LOWER lowercase
TRIM trim

All lessons in Beginner