![](/mysql-uppercase/cover_image.png)
The MySQL UPPER
and UCASE
functions are used to transform a string of characters into its all uppercase version.
You need to provide the string you wish to transform as the argument to the functions as shown below:
UPPER(str)
-- OR
UCASE(str)
For example, the following query transforms england
as ENGLAND
:
SELECT UPPER("england");
-- +------------------+
-- | UPPER("england") |
-- +------------------+
-- | ENGLAND |
-- +------------------+
The function can only transforms one string at a time, so passing multiple strings will result in an error:
SELECT UPPER("england", "wales");
-- ERROR 1582 (42000): Incorrect parameter count in the call to native function 'UPPER'
To transform multiple strings, you need to call the function for each string separated by a comma:
SELECT UPPER("england"), UPPER("wales");
-- +------------------+----------------+
-- | UPPER("england") | UPPER("wales") |
-- +------------------+----------------+
-- | ENGLAND | WALES |
-- +------------------+----------------+
Finally, you can also pass a column name as the argument to the UPPER
or UCASE
functions to run the function on each column value.
Suppose you have a table called countries
with the following data:
+----+------------------+
| id | name |
+----+------------------+
| 1 | england |
| 2 | wales |
| 3 | northern ireland |
| 4 | scotland |
+----+------------------+
You can pass the name
column into the UPPER
function as shown below:
SELECT UPPER(name) FROM countries;
The returned result set will be as follows:
+------------------+
| UPPER(name) |
+------------------+
| ENGLAND |
| WALES |
| NORTHERN IRELAND |
| SCOTLAND |
+------------------+
And that’s how you transform a string of characters into its uppercase version in MySQL.
If you want to do the opposite and transform a string into its lowercase version, then you can use the MySQL LOWER
function and its alias LCASE
function.