• TestingDocs
TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL CHAR_LENGTH Function

Overview

In this tutorial, we will learn about the MySQL CHAR_LENGTH Function. This function returns the
length of the string i.e the umber of characters in the string.

Syntax

The general the syntax for a function call includes the function name followed by parenthesis
(which contains the String argument):

CHAR_LENGTH(string_argument)

This function can be invoked with a string argument or column names. The function returns the number that is used in place of the function call when the expression is evaluated.

Examples

In the first example, we will call the function with a sample string argument. Let’s count the number of characters in the string ‘abcd’.

mysql> SELECT CHAR_LENGTH(‘abcd’);
+———————+
| CHAR_LENGTH(‘abcd’) |
+———————+
| 4 |
+———————+

MySQL CHAR_LENGTH Function

In the next example, we will calculate the number of characters in a table column. We will consider the
Country database table from the world MYSQL database. The Name column is a String datatype column CHAR/VARCHAR.

mysql> SELECT Name, CHAR_LENGTH(Name)
             -> FROM Country
             -> WHERE Continent = ‘North America’;

 

MySQL CHAR_LENGTH Function Column Name

There is a notable difference between CHAR_LENGTH and LENGTH functions.  CHAR_LENGTH() counts multi-byte character as a single character. For example, for a string containing seven 2-byte characters, LENGTH() returns 14, whereas CHAR_LENGTH() function returns 7.

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

MySQL /

How to secure your SQL Database: Tips and Tricks

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

‹ MySQL Trigonometry Functions› MySQL INSTR Function

Recent Posts

  • How to secure your SQL Database: Tips and Tricks
  • Shaping the Future of Development: Exploring Key Trends in Software Engineering
  • Improving Java Performance with Multithreading
  • Difference between PHP and JavaScript?
  • Bing Conversation Styles
  • ChatGPT Introduction
  • Open Source AI Frameworks
  • Artificial Intelligence Tools
  • Top AI Music Applications
  • Top AI Website Design Tools

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com