- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to lowercase the entire string keeping the first letter in uppercase with MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (1.32 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('JOhn'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('CHRIS'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('DAVID'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('RObert'); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------+ | Name | +--------+ | JOhn | | CHRIS | | DAVID | | RObert | +--------+ 4 rows in set (0.00 sec)
Following is the query to lowercase the entire string keeping the first letter in uppercase in MySQL −
mysql> update DemoTable -> set Name= CONCAT(UCASE(LEFT(Name, 1)), LCASE(SUBSTRING(Name, 2))); Query OK, 4 rows affected (0.30 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check all records from the table once again.
mysql> select *from DemoTable;
Output
+--------+ | Name | +--------+ | John | | Chris | | David | | Robert | +--------+ 4 rows in set (0.00 sec)
Advertisements