SQL UCASE函数

一、SQL UCASE函数 语法

SQL UCASE函数 以大写形式显示结构化查询语言中的所有字符串字符。它将小字符或一组小字符转换为大写字母。

语法1:此语法使用 UCASE 函数和 SQL 表的列名:

SELECT UCASE(Column_Name) AS Alias_Name FROM Table_Name;  

在此语法中,Column_Name 是该列的名称,其值将以大写形式显示。

语法2:此语法使用 UCASE 函数和一组小写字符(字符串):

SELECT UCASE(String);  

语法3:此语法使用带有单个小写字符的 UCASE 函数:

SELECT UCASE(lower_case_character);  

二、SQL UCASE函数 示例

示例 1:以下 SELECT 查询将以下字符串的所有字符转换为大写(ucase):

SELECT UCASE(yiidian is a good website);  

输出结果为:

YIIDIAN IS A GOOD WEBSITE

示例 2:以下 SELECT 查询无法更改以下字符串的字符,因为 UCASE 函数无法更改 SQL 中字符串的符号和整数。

SELECT UCASE(@#$12453@#);  

输出结果为:

@#$12453@#

示例 3:以下 SELECT 查询将小写字母转换为大写字母:

SELECT UCASE( New Delhi IS the Capital OF India);

输出结果为:

NEW DELHI IS THE CAPITAL OF INDIA

示例 4:以下 SELECT 查询在输出中以 UCASE 大小写显示字符“s”:

SELECT UCASE( s );  

输出结果为:

S

示例 5:此示例将 UCASE 函数与 SQL 表一起使用

在本例中,我们将创建一个新表,该表与 UCASE 字符串函数一起使用。

在 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 查询将 UCASE 函数与上述 Faculty_Info 表的 Faculty_Last_Name 列一起使用:

SELECT Faculty_Last_Name, UCASE(Faculty_Last_Name) AS UCASE_LastName FROM Faculty_Info;  

此 SQL 语句将上表中每个教师的姓氏转换为大写。

Faculty_Last_Name UCASE_LastName
sharma SHARMA
roy ROY
roy ROY
singhania SINGHANIA
sharma SHARMA
besas BESAS

以下 SELECT 查询将 UCASE 函数与上面 Faculty_Info 表中的 Faculty_Id 大于 1002 的那些学院的 Faculty_First_Name、Faculty_City 和 Faculty_Address 列一起使用:

SELECT Faculty_Id, UCASE(Faculty_First_Name), UCASE(Faculty_Address), UCASE(Faculty_City) FROM Faculty_Info WHERE Faculty_Id >1002; 

输出结果为:

Faculty_Id UCASE(Faculty_First_Name) UCASE(Faculty_Address) UCASE(Faculty_City)
1004 SAURABH SECTOR 128 MUMBAI
1005 SHIVANI VIVEK VIHAR KOLKATA
1006 AVINASH SARVODYA CALONY DELHI
1007 SHYAM KRISHNA NAGAR LUCKNOW

以下 SELECT 查询将 UCASE 函数与上面 Faculty_Info 表中的 Faculty_Salary 大于 30000 的那些学院的 Faculty_Last_Name 和 Faculty_Address 列一起使用:

SELECT Faculty_Id, UCASE(Faculty_Last_Name), Faculty_Dept_Id, UCASE(Faculty_Address), UCASE(Faculty_Salary) FROM Faculty_Info WHERE Faculty_Salary > 30000; 

输出结果为:

Faculty_Id Faculty_Last_Name Faculty_Dept_Id Faculty_Address Faculty_Salary
1002 roy 4002 nirman vihar 38000
1004 roy 4001 sector 128 45000
1005 singhania 4001 vivek vihar 42000
1007 besas 4003 krishna nagar 35000

热门文章

优秀文章