This article gives an overview of SQL UPPER function and SQL LOWER function to convert the character case as uppercase and lowercase respectively.
本文概述了将字符大小写分别转换为大写和小写SQL UPPER函数和SQL LOWER函数。
介绍 (Introduction )
Suppose you have an online shopping website. Customers visit the website and provide their necessary information while creating a login account. Each customer provides few mandatory information such as first name, last name, email address and residential address. Each customer is different so you cannot expect a similar format for all inputs.
假设您有一个在线购物网站。 客户访问网站并在创建登录帐户时提供他们的必要信息。 每个客户仅提供一些必填信息,例如名字,姓氏,电子邮件地址和居住地址。 每个客户都是不同的,因此您不能期望所有输入都使用相似的格式。
For example, you get the following entries in your SQL table. We do not see all words following a consistent pattern. It does not look good as well if you have to share the report daily to higher management for all newly enrolled customers.
例如,您在SQL表中获得以下条目。 我们没有看到所有单词都遵循一致的模式。 如果您必须每天向所有新注册客户的高级管理人员共享报告,则情况也不太好。
In the following table, you can see the different types of inputs from different customers. For example, in [First Name] column, we have Raj (First character capital), sonu (all small case characters) and PAUL (capital letters).
在下表中,您可以看到来自不同客户的不同类型的输入。 例如,在[名字]列中,我们有Raj(大写字母大写),sonu(所有小写字母)和PAUL(大写字母)。
First Name |
Last Name |
Email address |
Residential address |
Raj |
Gupta |
raj.gupta@abc.com |
140, high street, la |
sonu |
Kumar |
SONU.KUMAR@XYZ.com |
10,KING STREET, GA |
PAUL |
SMITH |
Paul.Smith@Abc.com |
20,New Market, SA |
名字 |
姓 |
电子邮件地址 |
居住地址 |
拉吉 |
古普塔 |
raj.gupta@abc.com |
洛杉矶高街140号 |
声纳 |
库玛 |
SONU.KUMAR@XYZ.com |
乔治亚国王街10号 |
保罗 |
史密斯 |
保罗·史密斯@ Abc.com |
20,New Market,SA |
You might think of a question at this point – Is it possible to covert the character case in SQL Server to an appropriate format.
您可能会想到一个问题–是否可以将SQL Server中的字符大小写转换为适当的格式。
Yes, it is quite possible. Let’s explore a few available scenarios in the further section of this article.
是的,这很有可能。 让我们在本文的后续部分中探讨一些可用的方案。
SQL UPPER函数 (SQL UPPER Function)
We use SQL UPPER function to convert the characters in the expression into uppercase. It converts all characters into capital letters.
我们使用SQL UPPER函数将表达式中的字符转换为大写。 它将所有字符转换为大写字母。
The syntax of SQL Upper function is:
SQL Upper函数的语法为:
SELECT UPPER(expression) FROM [Source Data]
Let’s use some examples for this function and view the output.
让我们使用此函数的一些示例并查看输出。
示例1:在单个单词中对所有小写字符使用UPPER功能 (Example 1: Use UPPER function with all lower case characters in a single word)
SELECT UPPER('sqlshack');
It gives the following output.
它给出以下输出。

示例2:对表达式中的所有小写字符使用UPPER函数 (Example 2: Use UPPER function with all lower case characters in an expression)
In this example, we use a string with Upper function, and it converts all letters in the string to uppercase.
在此示例中,我们使用具有Upper函数的字符串,并将字符串中的所有字母都转换为大写。
SELECT UPPER('learn sql server with sqlshack');
Output: It converts all characters for a string.
输出:它将所有字符转换为字符串。