Select*fromemp_tbl;+----+----------------+|Id|Name |+----+---------- -----"/> Select*fromemp_tbl;+----+----------------+|Id|Name |+----+---------- -----">
In fact, there is no function in MySQL that can only capitalize the first letter of a string. We need to use function nesting, for this case we can use UPPER() and LOWER() with SUBSTRING() function. To understand it, we use data from "emp_tbl" as shown below.
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)
As can be seen from the above result set, the first character of the name string is a lowercase letter. The following query capitalizes the first letter of a 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)
The above is the detailed content of How to capitalize only the first letter of a string with the help of MySQL function?. For more information, please follow other related articles on the PHP Chinese website!