SQL LCASE函数

SQL LCASE函数

这个字符串函数可以在结构化查询语言中显示所有小写字母。它将大写字母或一组大写字母转换为小写字母。

LCASE字符串函数的语法

语法1: 这种语法使用SQL表的列名与LCASE函数一起使用:

SELECT LCASE(Column_Name) AS Alias_Name FROM Table_Name;

在这个语法中,Column_Name是要显示为小写的列的名称。

语法2: 这个语法使用LCASE函数与一组大写字符(字符串):

SELECT LCASE(String);

语法2: 此语法使用LCASE函数与单个大写字符一起使用:

SELECT LCASE(lower_case_character);

HTML格式的LCASE字符串函数示例

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

SELECT LCASE(JAVATPOINT IS A GOOD WEBSITE);

输出:

javatpoint 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查询将大学教师的记录插入到 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查询在上面的Faculty_Info表中,使用LCASE函数与Faculty_First_Name、Faculty_City和Faculty_Address列,针对faculty_Id大于1002的教职员工。

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查询在上述Faculty_Info表中使用LCASE函数和Faculty_Last_Name和Faculty_Address列的工资大于30000的教职员工:

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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程