---
title: character_length function
description: Learn the syntax of the character\_length function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/character_length
---

# `character_length` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the character length of string data or number of bytes of binary data. This function is a synonym for [`char_length` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/char_length.md) and [`length` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/length.md).

## Syntax

```
character_length(expr)
```

## Arguments

* `expr`: A BINARY or STRING expression.

## Returns

The result type is INTEGER.

The length of string data includes the trailing spaces.
The length of binary data includes binary zeros.

## Examples

```sql
> SELECT character_length('Spark SQL ');
 10
> select character_length('床前明月光')
 5
```

## Related functions

* [`char_length` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/char_length.md)
* [`length` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/length.md)
