SQL UPPER函数
该字符串函数将Structured Query Language(结构化查询语言)中的所有字符串字符显示为大写。它将小字符或一组小字符转换为大写字母。
我们还可以将UPPER函数与SQL表的字符串字段一起使用。
UPPER字符串函数的语法
语法1: 此语法将UPPER函数与SQL表的列名称一起使用:
SELECT UPPER(Column_Name) AS Alias_Name FROM Table_Name;
在语法中,我们必须指定要在哪个列名上使用UPPER字符串函数。
语法2: 该语法使用UPPER函数和一组小写字符(字符串):
SELECT UPPER(String);
语法2: 这个语法使用UPPER函数和小写字符:
SELECT UPPER(lower_case_character);
UPPER String函数的示例
示例1:下面的SELECT查询将以下字符串的所有字符转换为大写:
SELECT UPPER(javatpoint is a good website);
输出:
JAVATPOINT IS A GOOD WEBSITE
示例2:以下SELECT查询无法改变以下字符串的字符,因为在SQL中UPPER函数无法改变字符串的符号和整数。
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查询将大学Faculty的记录插入到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 |