How the UCASE() function works in Mariadb?

The UCASE() function in MariaDB is used to convert a string to uppercase.

Posted on

The UCASE() 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 UCASE() function is as follows:

UCASE(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 UCASE() function.

SELECT UCASE('hello world') AS uppercase_string;

Output:

+------------------+
| uppercase_string |
+------------------+
| HELLO WORLD      |
+------------------+

The UCASE() function converted the string ‘hello world’ to ‘HELLO WORLD’.

Example 2: Converting a String with Mixed Cases

This example shows how the UCASE() function handles a string with mixed cases.

SELECT UCASE('Hello, World!') AS uppercase_string;

Output:

+------------------+
| uppercase_string |
+------------------+
| HELLO, WORLD!    |
+------------------+

The UCASE() 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 UCASE() 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, UCASE(name) AS uppercase_name FROM example;

Output:

+----------------+----------------+
| name           | uppercase_name |
+----------------+----------------+
| John Doe       | JOHN DOE       |
| Jane Smith     | JANE SMITH     |
| EXAMPLE STRING | EXAMPLE STRING |
+----------------+----------------+

The UCASE() function converted the values in the name column to uppercase.

Example 4: Converting a String with Special Characters

This example shows how the UCASE() function handles strings with special characters.

SELECT UCASE('Hello, World! 123@#$%^&*()') AS uppercase_string;

Output:

+----------------------------+
| uppercase_string           |
+----------------------------+
| HELLO, WORLD! 123@#$%^&*() |
+----------------------------+

The UCASE() function converted all alphabetic characters to uppercase while leaving the special characters and numbers unchanged.

Example 5: Combining UCASE() with Other Functions

This example demonstrates how to combine the UCASE() function with other string functions.

SELECT UCASE(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 UCASE() function converts the resulting string to uppercase.

The following are some functions related to the MariaDB UCASE() function:

  • MariaDB LCASE() function is used to convert a string to lowercase.
  • MariaDB UPPER() function is an alias for the UCASE() function and performs the same operation.
  • MariaDB LOWER() function is an alias for the LCASE() function and performs the same operation.

Conclusion

The UCASE() 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 UCASE() function provides a convenient solution.