SQL UPPER() Function
Last Updated :
18 Mar, 2024
SQL UPPER function is a string function that converts all the strings in the table to uppercase. The UPPER function in SQL is very useful for string formatting.
In this article, we will learn the basics of the UPPER function in SQL and understand its workings with examples of different use cases.
UPPER() Function
SQL UPPER function is an in-built function that changes lowercase characters or strings to capital cases. Certain characters like Integers(0-9) or special characters like (“@”, “-” “/”, “&” etc.) remain unchanged in the result.
It is used to display the output in CAPITAL CASE and is supported by all major SQL-based DBMSs.
Note: UPPER and UCASE functions perform the same operation on strings. In older versions of SQL, some databases (like Db2 DBMS)used the UCASE function, while others used the UPPER function. Now both the functions are supported by all major databases.
The UPPER function is supported in SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse, MySQL 4.0, Oracle, DB2, and all other major Database systems.
Example:
SELECT UPPER ("geeks")
Syntax
UPPER(input_text);
OR
UPPER(column_name);
Demo SQL Database
We will be using the following table in the examples:
ID
| NAME
|
---|
12@tEsla
| Elon
|
x
| Musk
|
Microsoft
| Bill
|
To create this table in your system,write the following queries:
MySQL
CREATE TABLE GFG_UPPER_DEMO(
Id Varchar(20),
Name varchar(20)
);
INSERT INTO GFG_UPPER_DEMO VALUES
("12@tEsla", "Elon"),
("x" ,"Musk"),
("Microsoft", "Bill") ;
SQL UPPER() Function Examples
Look at the examples below to understand how to use UPPER function in different use cases.
Example 1: Converting Character Literal to Uppercase
In the first column, we are printing the x value as it is, and in the second column we are printing the ID value after applying the UPPER function, and the UPPER function converted “x” into “X”.
SELECT "x" as "BEFORE UPPER() Function" , UPPER("x") as "AFTER UPPER() Function";
Output:
Converting Character Literal to Capital Case Using UPPER() function.
Example 2: Converting string to Uppercase
In the first column, we are printing the “Microsoft” word as it is, and in the second column we are printing the “Microsoft” value after applying the UPPER() function, and the UPPER function converted “Microsoft” into “MICROSOFT“.
Query:
SELECT "Microsoft" as "BEFORE UPPER() Function" , UPPER("Microsoft") as "AFTER UPPER() Function";
Output:
Converting Character Literal to Capital Case Using UPPER() function.
Example 3: Using UPPER Function on String Consisting of Special Characters, Integers, and Alphabets
SELECT "12@tEsla" as "BEFORE UPPER() Function" , UPPER("12@tEsla") as "AFTER UPPER() Function" ;
In the first column, we are printing the ID value as it is, and in the second column we are printing the ID value after applying the UPPER function, and “12@tEsla” is converted to “12@TESLA“. The special characters and Numerical characters remained the same, only the alphabets are converted into capital case.
Output:
Converting a String with Numerical characters and Special Characters into Capital Case using UPPER() function.
Example 4: Using UPPER function on a Column
SELECT ID as "BEFORE UPPER() Function" , UPPER(ID) as "AFTER UPPER() Function" FROM
GFG_UPPER_DEMO;
In this example. we passed a column name ID as an argument to the UPPER() function. It converts all the values present in the ID column and outputs. In the first column, we can see the ID values before using the UPPER() function. In the second column, We can see all the alphabetic characters get converted into Capital Cases. Integer and special characters remain as it is. As we can see, “x“, “Microsoft“, and “12@tEsla” are converted into “X“, “MICROSOFT“, and “12@TESLA” respectively.
Output:
Passing a column name to the UPPER() function and Converting it to Capital Case.
Key Takeaways about SQL UPPER()
- UPPER() function in SQL allows us to convert the string text into uppercase.
- It takes only one parameter and converts the entire string into upper case.
- It is similar to the UCASE() function.
- Special Characters like “@”, “%”, “+” etc. and numerical characters remain unchanged, only the lowercase alphabetical letters get transformed into uppercase.
Share your thoughts in the comments
Please Login to comment...