w3resource
MYSQL Tutorial

MySQL UCASE() function

UCASE() function

MySQL UCASE() coverts all the characters of a string to uppercase. The UCASE() is a synonym of UPPER()

Syntax:

UCASE (str)

The above function is a synonym for UPPER().

Syntax Diagram:

MySQL UCASE() Function - Syntax Diagram

MySQL Version: 5.6

Video Presentation

Example: MySQL UCASE() function

The following MySQL statement returns all the characters in the string to uppercase.

Code:

SELECT UCASE('myteststring');

Sample 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)

All String Functions

MySQL String Functions, slide presentation

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.