 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
How can we capitalize only first letter of a string with the help of MySQL function/s?
Actually, there is no single function in MySQL to capitalize only first letter of the string. We need to use nesting of functions and for this case, we can use UPPER() and LOWER() with SUBSTRING() functions. To understand it, we are using data, given as below, from ?emp_tbl'.
mysql> Select * from emp_tbl; +----+----------------+ | Id | Name | +----+----------------+ | 1 | rahul singh | | 2 | gaurav kumar | | 3 | yashpal sharma | | 4 | krishan kumar | | 5 | kuldeep rai | | 6 | munish nayak | +----+----------------+ 6 rows in set (0.00 sec)
We can see from the above result set that the first character of name string is in small letters. The following query will capitalize the first letter of string ?
mysql> Select CONCAT(UPPER(SUBSTRING(name,1,1)),LOWER(SUBSTRING(name,2))) AS Name from emp_tbl; +----------------+ | Name | +----------------+ | Rahul singh | | Gaurav kumar | | Yashpal sharma | | Krishan kumar | | Kuldeep rai | | Munish nayak | +----------------+ 6 rows in set (0.00 sec)
Advertisements
 