MySQL UPPER() Function
The MySQL UPPER() function is used to convert all the characters of a string to upper case letters.
This function can be useful in various scenarios such as formatting text for consistent comparisons, normalization, etc.
Syntax
Following is the syntax of MySQL UPPER() function −
UPPER(str)
Parameters
This function takes a string value as a parameter.
Return Value
This function returns the uppercase version of the given string.
Example
In the following example, we are converting the string 'tutorialspoint' to all uppercase letters −
SELECT UPPER('tutorialspoint');
Following is the output of the above code −
| UPPER('tutorialspoint') |
|---|
| TUTORIALSPOINT |
Example
To change the case of a binary string from lower to upper, you first need to convert it into a non-binary string and then proceed −
SELECT UPPER(CONVERT(BINARY 'tutorialspoint' USING utf8mb4));
The output obtained is as follows −
| UPPER(CONVERT(BINARY 'tutorialspoint' USING utf8mb4)) |
|---|
| TUTORIALSPOINT |
Example
If the argument passed to the UPPER() function is NULL, it returns NULL −
SELECT UPPER(NULL);
We get the output as follows −
| UPPER(NULL) |
|---|
| 0x |
Example
If we pass an empty string as an input, this functions returns an empty string to the output −
SELECT UPPER ("");
Following is the output of the above code −
| UPPER("") |
|---|
Example
If you pass a numerical value to this function, it returns the same value −
SELECT UPPER(55886);
The result produced is as shown below −
| UPPER(55886) |
|---|
| 55886 |
Example
You can also convert the lower case letters in the column of a table to upper case using the UPPER() function.
Let us create a table named "EMP" and insert records into it using CREATE and INSERT statements as shown below −
CREATE TABLE EMP( FIRST_NAME CHAR(20) NOT NULL, LAST_NAME CHAR(20), AGE INT, INCOME FLOAT );
Now, let us insert records into it using the INSERT statement −
INSERT INTO EMP VALUES
('Krishna', 'Sharma', 19, 2000),
('Raj', 'Kandukuri', 20, 7000),
('Ramya', 'Ramapriya', 25, 5000),
('Mac', 'Mohan', 26, 2000);
The EMP obtained is as follows −
| FIRST_NAME | LAST_NAME | AGE | INCOME |
|---|---|---|---|
| Krishna | Sharma | 19 | 2000 |
| Raj | Kandukuri | 20 | 7000 |
| Ramya | Ramapriya | 25 | 5000 |
| Mac | Mohan | 26 | 2000 |
Following query converts all the characters in the column 'FIRST_NAME' using the UPPER() function −
SELECT FIRST_NAME, LAST_NAME, AGE, UPPER(FIRST_NAME) as RESULT FROM EMP;
After executing the above code, we get the following output −
| FIRST_NAME | LAST_NAME | AGE | RESULT |
|---|---|---|---|
| Krishna | Sharma | 19 | KRISHNA |
| Raj | Kandukuri | 20 | RAJ |
| Ramya | Ramapriya | 25 | RAMYA |
| Mac | Mohan | 26 | MAC |