Tuesday 10 July 2018

Mysql UCASE() function

Mysql 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().
MySQL Version: 5.6
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)

0 comments:

Post a Comment