AppDividend
Latest Code Tutorials

SQL UPPER() Function: The Complete Guide

If you have an online shopping website. Customers visit the website and provide the necessary information while creating the login account. Each customer provides a few compulsory information such as first name, last name, phone number, email address, and residential address. Each customer is different, so you cannot expect a similar format for all inputs.

SQL UPPER() Function

SQL UPPER() is a built-in function used to convert all the characters in the source string to Uppercase characters. If any number is present in the string, then it remains unaffected. SQL UPPER() function converts a string to the upper-case.

For example, you get the following entries in an SQL table.

We do not see all words following a consistent pattern.

It does not look good if you have to share the report daily with higher management for all newly enrolled customers.

The SQL UPPER function converts all the letters in a string into uppercase. If you want to convert the string to lowercase, you use the LOWER function instead.

Syntax

SELECT UPPER (String);

Parameters

String: The source string whose characters must be replaced with Uppercase characters. It can be any literal character string, variable, character expression, or table column.

Example

Query 1

SELECT UPPER (‘AppDividend.Com’);

Output

APPDIVIDEND.COM

Query 2

SELECT UPPER (‘sql123sql’);

Output

SQL123SQL

As discussed above, numbers remain unaffected by the UPPER() function.

Let’s apply the UPPER function to a table.

Table: Employee

Emp_id Emp_name City State Salary
101 Rohit Patna Bihar 30000
201 Shivam Jalandhar Punjab 20000
301 Karan Allahabad Uttar Pradesh 40000
401 Suraj Kolkata West Bengal 60000
501 Akash Vizag Andhra Pradesh 70000

 

Suppose we want to change the characters of the City of each employee to Uppercase, then the following query has to be written.

Query 3

SELECT Emp_name, City, UPPER (City) 
AS UPPER_CITY from Employee;

Output

Emp_name City UPPER_CITY
Rohit Patna PATNA
Shivam Jalandhar JALANDHAR
Karan Allahabad ALLAHABAD
Suraj Kolkata KOLKATA
Akash Vizag VIZAG

 

As you can see above, the name of the City is converted to Uppercase characters.

MySQL UPPER() Function

In MySQL, the UPPER() function converts a string to upper-case.

Syntax

UPPER(text)

In this syntax, the text parameter can be a literal character string, variable, character string expression, or table column.

SQL Server UPPER() Function

The UPPER() function converts an input string into uppercase.

Syntax

The following shows the syntax of the UPPER() function:

UPPER(string)

In this syntax, the string parameter can be a literal character string, variable, character string expression, or table column.

The type of string must be implicitly convertible to VARCHAR. Otherwise, you must use the CAST() function to convert the string explicitly.

SQL Server UPPER() function returns the uppercase form of the input string.

Using the UPPER() function with literal strings

See the following query.

SELECT 
    UPPER('appdividend') result;

See the output.

result

APPDIVIDEND

That’s it for this tutorial.

Recommended Posts

SQL UNICODE()

SQL Replicate()

SQL Left Function

SQL Format

SQL LTRIM()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.