MySQL CHAR_LENGTH() Function

The CHAR_LENGTH() function returns the number of characters in a string. This function counts characters, not bytes. It is equivalent to CHARACTER_LENGTH().

Tutorials dojo strip

MySQL CHAR_LENGTH Function Syntax

SQL

MySQL CHAR_LENGTH Function Example

This query returns the number of characters in the string 'SQL Tutorial'.

SQL

Note: The CHAR_LENGTH() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.

MySQL CHAR_LENGTH Function Parameters

ParameterDescription
stringThe string to count the number of characters. Required.

MySQL CHAR_LENGTH Function Table Column Example

This query returns the number of characters in the first_name column for each patient.

SQL

Note: The CHAR_LENGTH() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.

MySQL CHAR_LENGTH Function Notes

  • The result is the number of characters, not bytes.
  • CHAR_LENGTH() is equivalent to CHARACTER_LENGTH().
  • Works in MySQL 4.0 and higher.

Tutorials dojo strip