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

# `char_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 [`character_length` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/character_length.md) and [`length` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/length.md).

## Syntax

```
char_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 char_length('Spark SQL ');
 10
> select char_length('床前明月光')
 5
```

## Related functions

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