SQL LCASE 函数

一、SQL LCASE 函数 语法

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

语法1:此语法使用带有 SQL 表的列名的 LCASE 函数:

SELECT LCASE(Column_Name) AS Alias_Name FROM Table_Name;  

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

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

SELECT LCASE(String);  

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

SELECT LCASE(lower_case_character);  

二、SQL LCASE 函数 示例

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

SELECT LCASE(YIIDIAN IS A GOOD WEBSITE);  

输出结果为:

yiidian is a good website

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

SELECT LCASE(@#$12453@#);  

输出结果为:

@#$12453@#

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

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

输出结果为:

new delhi is the capital of india

示例 4:以下 SELECT 查询在输出中显示小字符“S”:

SELECT LCASE( S);  

输出结果为:

s

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

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

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

SELECT Faculty_Last_Name, LCASE(Faculty_Last_Name) AS LCASE_LastName FROM Faculty_Info;  

此 SQL 语句将每个教师的姓氏转换为小写字母:

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

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

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

输出结果为:

Faculty_Id LCASE(Faculty_First_Name) LCASE(Faculty_Address) LCASE(Faculty_City)
1004 saurabh sector 128 mumbai
1005 shivani vivek vihar kolkata
1006 avinash sarvodya calony delhi
1007 shyam krishna nagar lucknow

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

SELECT Faculty_Id, LCASE(Faculty_Last_Name), Faculty_Dept_Id, LCASE(Faculty_Address), LCASE(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

热门文章

优秀文章