This tutorial explains MySQL UPPER()/UCASE() functions which convert the lowercase characters of a string to uppercase. We’ll describe the functioning of this method with the help of simple examples.
1. UPPER()/UCASE() Syntax
2. UPPER()/UCASE() to convert text to upper case
3. UPPER()/UCASE() on table data
4. UPPER()/UCASE() on binary text
Let’s now go through each of the sections one by one.
MySQL UPPER()/UCASE() Functions
As stated initially, UPPER() is a built-in MySQL function that changes a string value to upper case. So, let’s now see the details and check out how can we use it.
Syntax
Below is the signature of this method:
# MySQL Function to convert text to upper case UPPER(Given_string);
Below is the description of the parameter used in the above function.
+--------------+-------------------------------------+ | # Params | # Description | +--------------+-------------------------------------+ | Given_string | Input string argument in lower case | +-------------+--------------------------------------+
MySQL also provides UCASE() which is another function to convert a string to upper case. It takes some text input and produces the result in capitalized format.
# Another MySQL function to capitalize a string UCASE(Given_string);
Later, in examples, you’ll see that both UPPER() and UCASE() are producing the same output.
MySQL LOWER()/LCASE() Functions
MySQL UPPER()/UCASE() Examples
Let’s now unveil several examples addressing different situations.
Using UPPER()/UCASE() to convert text to upper
Both UPPER() and UCASE() functions can take a standard or alpha-numeric TEXT and convert it to upper case. See the below example.
SELECT UPPER('Python Programming'); SELECT UPPER('Python Version 3.6');
Check the result/outcome of the UPPER() function below.
1 MySQL Workbench PYTHON PROGRAMMING PYTHON VERSION 3.6
Next, we’ll run the same test using the MySQL UCASE() function.
SELECT UCASE('Python Programming'); SELECT UCASE('Python Version 3.6');
You can see that UCASE() also produced the same as UPPER() did.
1 MySQL Workbench PYTHON PROGRAMMING PYTHON VERSION 3.6
Calling UPPER()/UCASE() on table fields
In this example, we are applying the UPPER() on a table column. Here, we will print the company name in capital format.
-- Convert company_name field to upper case using UPPER() SELECT company_name, UPPER(company_name) uppercase FROM company_list ORDER BY company_name LIMIT 5;
After executing the above command, the output will be:
1 MySQL Workbench APPLE BING CA DELL GOOGLE
Let’s now use UCASE() on the same table and see what it does.
-- Convert company_name field to upper case using UCASE() SELECT company_name, UCASE(company_name) ucase FROM company_list ORDER BY company_name LIMIT 5;
After executing the above command, the output is the same:
1 MySQL Workbench APPLE BING CA DELL GOOGLE
Also Read: MySQL CONCAT to Concatenate Strings
MySQL UPPER()/UCASE() on binary text
MySQL types like BINARY, VARBINARY, and BLOB are binary text. The UPPER() function is not directly compatible with them.
Hence, we first have to make them compatible with the UPPER() function. See the example below.
-- Convert binary text to string and then in upper case using UPPER() SET @binary_data = BINARY 'Binary Sample Text'; SELECT UPPER(@binary_data), UPPER(CONVERT(@binary_data USING UTF8MB4)) UPPER_FUNC;
After execution, we get this:
1 MySQL Workbench Binary Sample Text BINARY SAMPLE TEXT
Similarly, we’ll now call UCASE() instead of UPPER() for the above test case.
-- Convert binary text to string and then in upper case using UCASE() SET @binary_data = BINARY 'Binary Sample Text'; SELECT UCASE(@binary_data), UCASE(CONVERT(@binary_data USING UTF8MB4)) UCASE_FUNC;
After execution, we get this:
1 MySQL Workbench Binary Sample Text BINARY SAMPLE TEXT
We hope that after wrapping up this tutorial, you will feel comfortable using the MySQL UPPER() and UCASE() functions. However, you may practice more with examples to gain confidence.
Also, to learn SQL from scratch to depth, read our step-by-step MySQL tutorial.