How the UPPER() function works in Mariadb?
The UPPER()
function in MariaDB is used to convert a string to uppercase.
The UPPER()
function in MariaDB is used to convert a string to uppercase. It takes a string as input and returns a new string with all the characters converted to their uppercase equivalents.
Syntax
The syntax for the MariaDB UPPER()
function is as follows:
UPPER(str)
str
: The input string to be converted to uppercase.
The function returns the uppercase version of the input string.
Examples
Example 1: Converting a Simple String to Uppercase
This example demonstrates how to convert a simple string to uppercase using the UPPER()
function.
SELECT UPPER('hello world') AS uppercase_string;
Output:
+------------------+
| uppercase_string |
+------------------+
| HELLO WORLD |
+------------------+
The UPPER()
function converted the string ‘hello world’ to ‘HELLO WORLD’.
Example 2: Converting a String with Mixed Cases
This example shows how the UPPER()
function handles a string with mixed cases.
SELECT UPPER('Hello, World!') AS uppercase_string;
Output:
+------------------+
| uppercase_string |
+------------------+
| HELLO, WORLD! |
+------------------+
The UPPER()
function converted all characters, including uppercase letters, to uppercase.
Example 3: Converting a String from a Table Column
This example demonstrates how to use the UPPER()
function to convert a string column in a table to uppercase.
DROP TABLE IF EXISTS example;
CREATE TABLE example (name VARCHAR(50));
INSERT INTO example VALUES ('John Doe'), ('Jane Smith'), ('EXAMPLE STRING');
SELECT name, UPPER(name) AS uppercase_name FROM example;
Output:
+----------------+----------------+
| name | uppercase_name |
+----------------+----------------+
| John Doe | JOHN DOE |
| Jane Smith | JANE SMITH |
| EXAMPLE STRING | EXAMPLE STRING |
+----------------+----------------+
The UPPER()
function converted the values in the name
column to uppercase.
Example 4: Converting a String with Special Characters
This example shows how the UPPER()
function handles strings with special characters.
SELECT UPPER('Hello, World! 123@#$%^&*()') AS uppercase_string;
Output:
+----------------------------+
| uppercase_string |
+----------------------------+
| HELLO, WORLD! 123@#$%^&*() |
+----------------------------+
The UPPER()
function converted all alphabetic characters to uppercase while leaving the special characters and numbers unchanged.
Example 5: Combining UPPER()
with Other Functions
This example demonstrates how to combine the UPPER()
function with other string functions.
SELECT UPPER(CONCAT('Hello', ', ', 'World!')) AS uppercase_string;
Output:
+------------------+
| uppercase_string |
+------------------+
| HELLO, WORLD! |
+------------------+
In this example, the CONCAT()
function is used to concatenate three strings, and then the UPPER()
function converts the resulting string to uppercase.
Related Functions
- MariaDB
LOWER()
function is used to convert a string to lowercase. - MariaDB
UCASE()
function performs the same operation asUPPER()
and converts a string to uppercase. - MariaDB
LCASE()
function performs the opposite operation ofUPPER()
and converts a string to lowercase.
Conclusion
The UPPER()
function in MariaDB is a straightforward way to convert strings to uppercase. By understanding the syntax and usage examples, you can easily incorporate this function into your SQL queries and data manipulation tasks. Whether you need to standardize data formatting, perform case-insensitive comparisons, or simply convert text to uppercase for presentation purposes, the UPPER()
function provides a convenient solution.