MySQL UPPER Function

Created with Sketch.

MySQL UPPER Function

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

MySQL UPPER() function overview

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.

A) Using MySQL UPPER() to convert a literal string to upper

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)

B) Using MySQL UPPER() to 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:

Dealing with 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 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.

In this tutorial, you have learned how to use the MySQL UPPER() function to convert a string to uppercase.

Leave a Reply

Your email address will not be published. Required fields are marked *