MySQL UPPER() Function

Summary: in this tutorial, you will learn how to use the MySQL UPPER() function to convert a string to uppercase.

Introduction to MySQL UPPER() function

The UPPER() function returns the uppercase of a specified string argument. The following shows the syntax of the UPPER() function:

UPPER(str)Code language: SQL (Structured Query Language) (sql)

In this syntax, the str is the argument to be converted to the uppercase.

Besides the UPPER() function, you can use the UCASE() function to convert a string to uppercase:

UCASE(str)Code language: SQL (Structured Query Language) (sql)

The results of both functions are the same.

Note that to convert a string to lowercase, you use the LOWER() function.

MySQL UPPER() function examples

Let’s take some examples of using the MySQL UPPER() function.

1) Using the UPPER() to convert a literal string to uppercase

The following example uses the UPPER() function to convert the string MySQL to uppercase:

SELECT 
    UPPER('MySQL');
Code language: SQL (Structured Query Language) (sql)

Here is the output:

+----------------+
| UPPER('MySQL') |
+----------------+
| MYSQL          |
+----------------+
1 row in set (0.00 sec)
Code language: SQL (Structured Query Language) (sql)

2) Using the UPPER() function with data in the table

This example uses the UPPER() function to convert the last name of employees to uppercase.

SELECT 
    lastname, 
    UPPER(lastname) uppercase
FROM
    employees
ORDER BY 
    lastname
LIMIT 10;Code language: SQL (Structured Query Language) (sql)

The following picture shows the partial output:

MySQL UPPER Function

Handling binary string data

The UPPER() function is ineffective when applied to the binary strings such as BINARY, VARBINARY, and BLOB.

Therefore, before passing a binary string to the UPPER() function, you need to convert the string to a nonbinary string as shown in the following example:

SET @str = BINARY 'Binary String';
SELECT UPPER(@str), UPPER(CONVERT(@str USING utf8mb4)) uppercase;Code language: SQL (Structured Query Language) (sql)

Here is the output:

+---------------+---------------+
| UPPER(@str)   | uppercase     |
+---------------+---------------+
| Binary String | BINARY STRING |
+---------------+---------------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)

As clearly shown from the output, the UPPER() function has no effect on the binary string.

Summary

  • Use the MySQL UPPER() function to convert a string to uppercase.
Was this tutorial helpful?