MySQL UCASE() function
UCASE() function
MySQL UCASE() coverts all the characters of a string to uppercase. The UCASE() is a synonym of UPPER()
This function is useful in -
- Uppercase conversion: It allows you to convert a string to uppercase.
- Case-insensitive comparison: UCASE() can be used for case-insensitive string comparison.
- Data normalization: UCASE() is often used in data normalization tasks to convert strings to a consistent case.
Syntax:
UCASE (str)
The above function is a synonym for UPPER().
Syntax Diagram:
MySQL Version: 8.0
Example: MySQL UCASE() function
The following MySQL statement returns all the characters in the string to uppercase.
Code:
SELECT UCASE('myteststring');
Output:
mysql> SELECT UCASE('myteststring'); +-----------------------+ | UCASE('myteststring') | +-----------------------+ | MYTESTSTRING | +-----------------------+ 1 row in set (0.01 sec)
MySQL: Capitalize first letter of a string
We have a table called test1 with following records :
mysql> SELECT * FROM test1;
+-----------+ | test_char | +-----------+ | abcd | | WxyZ | | scott | | ROBIN | +-----------+ 4 rows in set (0.00 sec)
Now we want to update the above data where the first character will be in upper case i.e. 'abcd' will be 'Abcd', 'WxyZ' will be 'WxyZ' and so on. See the following MySQL statement:
mysql> UPDATE test1 SET test_char = CONCAT(UCASE(LEFT(test_char, 1)), SUBSTRING(test_char, 2)); Query OK, 2 rows affected (0.03 sec) Rows matched: 4 Changed: 2 Warnings: 0 mysql> SELECT * FROM test1;
+-----------+ | test_char | +-----------+ | Abcd | | WxyZ | | Scott | | ROBIN | +-----------+ 4 rows in set (0.00 sec)
Video Presentation:
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mysql/string-functions/mysql-ucase-function.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics