In this tutorial, we will look at how to use the MySQL upper function. This in-built MySQL function takes a string and returns a new string with all the characters converted to uppercase according to the mapping of the character set which is currently in use.
For the vast majority of cases, this means that the MySQL upper function will take the letters of the alphabet and return the capitalisation of these letters. The reasons one may want to convert strings to uppercase using MySQL may vary, but whatever your need, the following MySQL tutorial will show you how to do it properly.
The upper function in MySQL is very straightforward and takes a single parameter as the argument.
-- Simply pass the string that you want to be converter to uppercase UPPER(string);
Now that the syntax for the upper function is out of the way we can proceed to the examples.
Look at the examples below of using the MySQL upper function.
SELECT UPPER('TutorialArena'); -- gives 'TUTORIALARENA'
Here are some other examples of the MySQL upper function at work:
SELECT UPPER('HaHa Lol'); -- gives 'HAHA LOL'
SELECT UPPER('abcdXYz'); -- gives 'ABCDXYZ'
As you can see the function is pretty straightforward to use. Modify the examples above and try them for yourself to see how they work.
Just as with the MySQL lower function, the MySQL upper function does not work on binary strings such as strings of the type BINARY, VARBINARY, and BLOB. If we wanted to convert a string of one of those types to uppercase we would need to convert it to a non-binary string first.
The following example demonstrates the procedure to get the function to work on a binary string:
SET @string = BINARY 'Tutorial Arena'; SELECT UPPER(@string); -- Gives the same 'Tutorial Arena' SELECT UPPER(CONVERT(@string USING latin1)); -- Gives 'TUTORIAL ARENA'
And there you have it. We hope you found this MySQL tutorial on the UPPER function useful.