The MySQL UPPER function is a built-in string function that is used to convert all the characters in a given string to uppercase. This function is particularly useful when you want to standardize the case of characters in a string for comparison or display purposes.
Syntax
The syntax for the UPPER function is straightforward:
UPPER(str)
Here, “str” is the string or expression that you want to convert to uppercase. The function returns a new string where all the alphabetic characters in the original string are converted to uppercase.
Example
Let’s look at a simple example:
SELECT UPPER('Hello, World!') AS UppercaseString;
This query would return:
+-------------------+ | UppercaseString | +-------------------+ | HELLO, WORLD! | +-------------------+
In this example, the UPPER function transformed the original string ‘Hello, World!’ into its uppercase equivalent.
You can also use the UPPER function in combination with other SQL statements. For instance, you might use it in a WHERE clause to perform a case-insensitive search:
SELECT * FROM employees WHERE UPPER(employee_name) = UPPER('john doe');
This query retrieves all records from the “employees” table where the “employee_name” is case-insensitively equal to ‘john doe’. The UPPER() function ensures that the comparison is not affected by the case of the characters in the “employee_name” column.
In summary, the MySQL UPPER function is a valuable tool for manipulating string data, especially when case consistency is crucial for accurate comparisons or when you need to present data in a standardized format.