SQL UPPER()

The SQL UPPER() function converts all characters in a specified string to uppercase.

This function is useful for standardizing text data, such as names or codes, for case-insensitive comparison or consistent display.

The UPPER() function is supported across major SQL databases, including SQL Server, MySQL, PostgreSQL, and Oracle.

In this tutorial, we will go through SQL UPPER() String function, its syntax, and how to use this function in SQL statements for string operations, with the help of well detailed examples.


Syntax of SQL UPPER() Function

The basic syntax of the SQL UPPER() function is:

</>
Copy
UPPER(string);

Each part of this syntax has a specific purpose:

  • string: The text that you want to convert to uppercase. This can be a column, variable, or literal string.

The UPPER() function returns the input string with all characters converted to uppercase.


Setup for Examples: Creating the Database and Table

We’ll create a sample customers table with fields first_name, last_name, and country. Follow these steps using MySQL or any SQL environment to set up the data for the UPPER() function examples.

1. First, create a new database called company:

</>
Copy
CREATE DATABASE company;

2. Select the company database to work with:

</>
Copy
USE company;

3. Create a table named customers with the fields customer_id, first_name, last_name, and country:

</>
Copy
CREATE TABLE customers (
    customer_id INT PRIMARY KEY AUTO_INCREMENT,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    country VARCHAR(50)
);

4. Insert sample data into the customers table to use with the UPPER() function examples:

</>
Copy
INSERT INTO customers (first_name, last_name, country)
VALUES
('Alice', 'Johnson', 'usa'),
('Bob', 'Smith', 'Canada'),
('Charlie', 'Brown', 'UsA'),
('David', 'Lee', 'Australia'),
('Eve', 'Martinez', 'usa');