SQL UPPER 函数
一、SQL UPPER 函数 语法
SQL UPPER 函数 以大写形式显示结构化查询语言中的所有字符串字符。它将小字符或一组小字符转换为大写字母。
我们还可以对 SQL 表的字符串字段使用 UPPER 函数。
语法1:此语法将 UPPER 函数与 SQL 表的列名一起使用:
SELECT UPPER(Column_Name) AS Alias_Name FROM Table_Name;
在语法中,我们必须指定要在其上使用 UPPER 字符串函数的列名。
语法2:此语法使用 UPPER 函数和一组小写字符(字符串):
SELECT UPPER(String);
语法3:此语法使用带有单个小写字符的 UPPER 函数:
SELECT UPPER(lower_case_character);
二、SQL UPPER 函数 示例
示例 1:以下 SELECT 查询将以下字符串的所有字符转换为大写:
SELECT UPPER(yiidian is a good website);
结果为:
YIIDIAN IS A GOOD WEBSITE
示例 2:以下 SELECT 查询无法更改以下字符串的字符,因为 UPPER 函数无法更改 SQL 中字符串的符号和整数。
SELECT UPPER(@#$12453@#);
结果为:
@#$12453@#
示例 3:以下 SELECT 查询将小写字母转换为大写字母:
SELECT UPPER( New Delhi IS the Capital OF India);
结果为:
NEW DELHI IS THE CAPITAL OF INDIA
示例 4:以下 SELECT 查询在输出中以大写形式显示字符“s”:
SELECT UPPER( s );
结果为:
S
示例 5:此示例对 SQL 表使用 UPPER 函数
在此示例中,我们将创建一个新表,其字符串列将包含小写字符。
在 SQL 数据库中创建新表的语法如下:
CREATE TABLE table_name
(
1st_Column Data Type (character_size of 1st Column),
2nd_Column Data Type (character_size of the 2nd column ),
3rd_Column Data Type (character_size of the 3rd column),
...
Nth_Column Data Type (character_size of the Nth column)
);
以下 CREATE 语句创建Faculty_Info表:
CREATE TABLE Faculty_Info
(
Faculty_ID INT NOT NULL PRIMARY KEY,
Faculty_First_Name VARCHAR (100),
Faculty_Last_Name VARCHAR (100),
Faculty_Dept_Id INT NOT NULL,
Faculty_Address Varchar(120),
Faculty_City Varchar (80),
Faculty_Salary INT
);
下面的 INSERT 语句将大学 Faculties 的记录插入到Faculty_Info表中:
INSERT INTO Faculty_Info (Faculty_ID, Faculty_First_Name, Faculty_Last_Name Faculty_Dept_Id, Faculty_Address, Faculty_City, Faculty_Salary) VALUES (1001, arush, sharma, 4001, aman vihar, delhi, 20000);
INSERT INTO Faculty_Info (Faculty_ID, Faculty_First_Name, Faculty_Last_Name Faculty_Dept_Id, Faculty_Address, Faculty_City, Faculty_Salary) VALUES (1002, bulbul, roy, 4002, nirman vihar, delhi, 38000 );
INSERT INTO Faculty_Info (Faculty_ID, Faculty_First_Name, Faculty_Last_Name Faculty_Dept_Id, Faculty_Address, Faculty_City, Faculty_Salary) VALUES (1004, saurabh, sharma, 4001, sector 128, mumbai, 45000);
INSERT INTO Faculty_Info (Faculty_ID, Faculty_First_Name, Faculty_Last_Name Faculty_Dept_Id, Faculty_Address, Faculty_City, Faculty_Salary) VALUES (1005, shivani, singhania, 4001, vivek vihar, kolkata, 42000);
INSERT INTO Faculty_Info (Faculty_ID, Faculty_First_Name, Faculty_Last_Name Faculty_Dept_Id, Faculty_Address, Faculty_City, Faculty_Salary) VALUES (1006, avinash, sharma, 4002, sarvodya calony, delhi, 28000);
INSERT INTO Faculty_Info (Faculty_ID, Faculty_First_Name, Faculty_Last_Name Faculty_Dept_Id, Faculty_Address, Faculty_City, Faculty_Salary)VALUES (1007, shyam, besas, 4003, krishna nagar, lucknow, 35000);
以下 SELECT 语句显示上述Faculty_Info表的插入记录:
SELECT * FROM Faculty_Info;
输出结果为:
Faculty_Id | Faculty_First_Name | Faculty_Last_Name | Faculty_Dept_Id | Faculty_Address | Faculty_City | Faculty_Salary |
---|---|---|---|---|---|---|
1001 | arush | sharma | 4001 | aman vihar | delhi | 20000 |
1002 | bulbul | roy | 4002 | nirman vihar | delhi | 38000 |
1004 | saurabh | roy | 4001 | sector 128 | mumbai | 45000 |
1005 | shivani | singhania | 4001 | vivek vihar kolkata 42000 | ||
1006 | avinash | sharma | 4002 | sarvodya calony | delhi | 28000 |
1007 | shyam | besas | 4003 | krishna nagar | lucknow | 35000 |
以下 SELECT 查询将 UPPER 函数与上述 Faculty_Info 表的 Faculty_Last_Name 列一起使用:
SELECT Faculty_Last_Name, UPPER(Faculty_Last_Name) AS UPPER_LastName FROM Faculty_Info;
此 SQL 语句将上表中每个学院的姓氏转换为大写。
Faculty_Last_Name | UPPER_LastName |
---|---|
sharma | SHARMA |
sroy | ROY |
sroy | ROY |
ssinghania | SINGHANIA |
ssharma | SHARMA |
sbesas | BESAS |
以下 SELECT 查询将 UPPER 函数与上面 Faculty_Info 表中的 Faculty_Id 大于 1002 的那些学院的 Faculty_First_Name、Faculty_City 和 Faculty_Address 列一起使用:
SELECT Faculty_Id, UPPER(Faculty_First_Name), UPPER(Faculty_Address), UPPER(Faculty_City) FROM Faculty_Info WHERE Faculty_Id >1002;
输出借给我为:
Faculty_Id | UPPER(Faculty_First_Name) | UPPER(Faculty_Address) | UPPER(Faculty_City) |
---|---|---|---|
1004 | SAURABH | SECTOR 128 | MUMBAI |
1005 | SHIVANI | VIVEK VIHAR | KOLKATA |
1006 | AVINASH | SARVODYA CALONY | DELHI |
1007 | SHYAM | KRISHNA NAGAR | LUCKNOW |
热门文章
优秀文章