How can I convert a string to uppercase or lowercase in SQL?

Learn SQL with Udemy

For an instructor lead, in-depth look at learning SQL click below.


In SQL programming, converting strings to either uppercase or lowercase can be achieved using in-built functions designed for this purpose. This conversion can be handy when performing data cleaning, manipulation and comparison tasks. In this blog post, we’re going to explore two key SQL functions: UPPER() and LOWER().

1. The UPPER() Function

The UPPER() function in SQL is used to convert all letters in a specified string to uppercase. Here’s the simple syntax:

Let’s look at a practical example:

In the above SQL query, the UPPER() function will convert all customer names in the “CustomerName” column to uppercase, and the alias “UpperCaseCustomerName” will be used to display the resultant column.

2. The LOWER() Function

Similarly, SQL’s LOWER() function is used to convert all text in a specified string to lowercase. Here is its syntax:

And here’s how to use it:

The LOWER() function here will change all customer names in the “CustomerName” column to lowercase, with the alias “LowerCaseCustomerName” being used to display the column’s output.

Conclusion

As a SQL programmer, understanding the use of string functions like UPPER() and LOWER() can significantly speed up your data manipulation and comparison tasks. Remember, these functions can be used on any text column in your database. Happy coding!

Leave a Comment