
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to get the character length for all the values in a column?
To get the character length, use the CHAR_LENGTH() method. Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (1.04 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+--------+ | Name | +--------+ | John | | Robert | | Bob | | David | +--------+ 4 rows in set (0.00 sec)
Get the character length −
mysql> select char_length(Name) from DemoTable;
Output
This will produce the following output −
+-------------------+ | char_length(Name) | +-------------------+ | 4 | | 6 | | 3 | | 5 | +-------------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to get the length of all columns and display the result in a single new column?
- MySQL query to set current date in the datetime field for all the column values
- Get multiple count in a single MySQL query for specific column values
- How to set all values in a single column MySQL Query?
- MySQL query to get all characters before a specific character hyphen
- MySQL query to select column values ending with certain character/number?
- MySQL query to get first two highest column values from a table?
- MySQL query to update all the values in a column with numeric incremental values like John1, John2, John3, etc.
- Add a character in the end to column values with MySQL SELECT?
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- MySQL query to increment one of the column values
- Set 'alias' for all the column names in a single MySQL query
- Setting column values as column names in the MySQL query result?
- Get row data for the lowest and highest values in a MySQL column
- Get all the records with two different values in another column with MySQL

Advertisements