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
.
id | first_name | last_name | favorite_car |
1 | Alan | Jackson | Honda Civic |
2 | Elisa | Thomson | TOYOTA Camry |
3 | Mary | Martines | Nissan rogue |
4 | Chris | Brown | ford focus |
5 | Adam | Spring | Ram 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 carFROM 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.
FAQs
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.
How do I get only capital letters from a string in SQL? ›
SQL Server UPPER() Function
The UPPER() function converts a string to upper-case.
How do I format a SQL query to uppercase? ›
To format an SQL text, select it and press Ctrl+Shift+F or right-click the selected text and click Format -> Format SQL on the context menu. To format a script to upper or lower case, highlight the SQL text, then right-click it and click Format -> To Upper Case / To Lower Case, respectively, on the context menu.
How do I convert an entire string to uppercase? ›
Use string. upper() to convert a string to uppercase, and string. lower() to convert a string to lowercase.
How do I convert SQL code to uppercase? ›
If you wanted to convert the name column to uppercase, you would use the following query: SELECT UPPER(name) FROM users; This query would return the result JOHN, JANE, JOHN, BOB, since all of the names in the table have been converted to uppercase.
How to convert string to proper case in SQL? ›
However, you can use a combination of LOWER(), UPPER(), CONCAT(), and SUBSTRING() functions to accomplish this. PostgreSQL: PostgreSQL provides the INITCAP() function, which converts the first letter of each word in a string to uppercase and the rest to lowercase.
What is the shortcut for capitalize all letters in SQL? ›
- Upper Case : ctr + shift + U.
- Lower Case : ctr + shift + L.
How do you capitalize all words in SQL? ›
UPPER(): Converts all letters in a string to uppercase. LOWER(): Converts all letters in a string to lowercase.
How do I convert only the first letter to uppercase in SQL? ›
The UCASE function is used to convert the first letter of each word to uppercase, and LCASE is used to convert the rest of the word to lowercase. This is then concatenated together using the CONCAT function.
How do you change all values to uppercase in SQL? ›
The UPPER() function in SQL Server is a useful tool for converting all characters in a string to uppercase. This function is essential for ensuring uniform text formatting and for performing case-insensitive comparisons.
Similar to UPPER( ) and LOWER( ), PROPER( ) would take a text string as an argument, and convert it to “Proper Case”, where the first letter of every work is upper-case, and subsequent letters in the word are lower-case.
How do you convert to uppercase in MySQL query? ›
MySQL UPPER() Function
The UPPER() function converts a string to upper-case. Note: This function is equal to the UCASE() function.
How do I change all text to uppercase? ›
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and then press fn+ SHIFT + F3 until the style you want is applied.
What converts all letters in a text string to uppercase? ›
By using upper() method you can convert a string to all uppercase. You can easily convert text to uppercase, lowercase, or reverse case using this tool.
How do you convert string to uppercase in regular expression? ›
A \U in front of a capture in the regex replacement will replace the text with an upper case version, and \L will lower case it. For example, if you search Lorem and replace with \U$0 , that would indicate that the whole of the matched text (represented by $0 ) should be replaced uppercase.
How do I convert a list of strings to uppercase? ›
Performing the . upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.
How do you convert a character to uppercase in a string? ›
In this example, the toupper() function converts each lowercase character in a given string to its uppercase equivalent. The str variable first initializes with the string “Hello, world!”, and then each character in the string passes as an argument to the toupper() function using a while loop.
How do you return the string in uppercase? ›
The toUpperCase() method returns the value of the string converted to uppercase. This method does not affect the value of the string itself since JavaScript strings are immutable.