

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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
- MySQL query to get all characters before a specific character hyphen
- How to set all values in a single column MySQL Query?
- MySQL query to select column values ending with certain character/number?
- Add a character in the end to column values with MySQL SELECT?
- MySQL query to increment one of the column values
- Get row data for the lowest and highest values in a MySQL column
- Set 'alias' for all the column names in a single MySQL query
- Get the sum of last 3 digits from all the values in a column with MySQL
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- 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.
- Setting column values as column names in the MySQL query result?
Advertisements