Back to cookbooks list Articles Cookbook

How to Convert a String to Uppercase in SQL

  • UPPER

Problem

You would like to convert a string to uppercase in SQL.

Example

Our database has a table named questionnaire with data in the following columns: id, first_name, last_name, and favorite_car.

idfirst_namelast_namefavorite_car
1AlanJacksonHonda Civic
2ElisaThomsonTOYOTA Camry
3MaryMartinesNissan rogue
4ChrisBrownford focus
5AdamSpringRam PICKUP

Our table stores the make and model of the favorite car for each person who filled out our questionnaire. Notice that the style in which these strings are written is inconsistent.

Solution 1

SELECT UPPER(favorite_car) AS car
FROM questionnaire;

This query returns each car name in uppercase:

car
HONDA CIVIC
TOYOTA CAMRY
NISSAN ROGUE
FORD FOCUS
RAM PICKUP

Discussion

If you want to display a string in uppercase, use the SQL UPPER() function. This function takes only one argument: the string column that you want to convert to uppercase.

Recommended courses:

Recommended articles:

See also: