# length

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: length
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/string-functions/length
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/string-functions/length.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/string-functions/length.adoc
description: Use the `length()` function to find the length of a string (for example, the number of characters in a given string).
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/length.md -->

Use the `length()` function to find the length of a string (for example, the number of characters in a given string). It accepts a string as a parameter. The syntax of the length function is:

```sql
LENGTH(string)
```

The input type is a string, and the return type is int, as it returns the number of characters.

**Special cases:**

-   If a NULL value is passed in the function. (For example, `LENGTH(NULL)`, it returns `NULL`).

-   If the parameter is an empty string `LENGTH('')`, it returns 0.

-   If the parameter is a space character `LENGTH(' ')`, not empty or NULL, it returns 1 as it is not empty anymore.


## [](#examples)Examples

### [](#basic-length-function)Basic `length()` function

This example uses the `length()` function to find out the length of a string text:

```sql
SELECT LENGTH ('Redpanda SQL Tutorial');
```

The query returns:

```sql
+------------+
| length     |
+------------+
| 21         |
+------------+
```

### [](#length-function-using-columns)`length()` function using columns

The following example uses the `length()` function on a `personal_details` table containing `id`, `first_name`, `last_name`, and `gender` columns for retail store employees.

```sql
CREATE TABLE personal_details (
  id int,
  first_name text,
  last_name text,
  gender text
);
INSERT INTO personal_details
    (id, first_name, last_name, gender)
VALUES
    (1,'Mark','Wheeler','M'),
    (2,'Tom','Hanks','M'),
    (3,'Jane','Hopper','F'),
    (4,'Emily','Byers','F'),
    (5,'Lucas','Sinclair','M');
```

```sql
SELECT * FROM personal_details;
```

The query shows this table:

```sql
+-----+-------------+-------------+----------+
| id  | first_name  | last_name   | gender   |
+-----+-------------+-------------+----------+
| 1   | Mark        | Wheeler     | M        |
| 2   | Tom         | Hanks       | M        |
| 3   | Jane        | Hopper      | F        |
| 4   | Emily       | Byers       | F        |
| 5   | Lucas       | Sinclair    | M        |
+-----+-------------+-------------+----------+
```

The query returns the last name and the length of the last name from the personal\_details table, where the length of the last\_name is greater than 5.

```sql
SELECT last_name,length(last_name)
AS "Length of Last Name"
FROM personal_details
WHERE LENGTH(last_name) > 5;
```

The output displays all those items in the last\_name column with a length of more than 5 characters:

```sql
+---------------+-----------------------+
| last_name     | Length of Last Name   |
+---------------+-----------------------+
| Wheeler       | 7                     |
| Hopper        | 6                     |
| Sinclair      | 8                     |
+---------------+-----------------------+
```