SQL LOWER 函数
一、SQL LOWER 函数 语法
SQL LOWER 函数 以小写形式显示结构化查询语言中的所有字符和字符串。它将小字符或一组小字符转换为大写字母。
我们还可以对 SQL 表的字符串字段使用 LOWER 函数。
语法1:此语法将 LOWER 函数与 SQL 表的列名一起使用:
SELECT LOWER(Column_Name) AS Alias_Name FROM Table_Name;
在语法中,我们必须指定要在其上使用 LOWER 字符串函数的列名。
语法2:此语法使用 LOWER 函数和一组大写字符(字符串):
SELECT LOWER(String);
语法3:此语法使用带有单个大写字符的 LOWER 函数:
SELECT LOWER(upper_case_character);
二、SQL LOWER 函数 示例
示例 1:以下 SELECT 查询将以下字符串的所有字符转换为小写:
SELECT LOWER(YIIDIAN IS A GOOD WEBSITE);
输出结果为:
yiidian is a good website
示例 2:以下 SELECT 查询无法更改以下字符串的字符,因为 LOWER 函数无法更改 SQL 中字符串的符号和整数。
SELECT LOWER(@#$12453@#);
输出结果为:
@#$12453@#
示例 3:以下 SELECT 查询将大写字母转换为小写字母:
SELECT LOWER(New Delhi IS the Capital OF INDIA);
输出结果为:
new delhi is the capital of india
示例 4:以下 SELECT 查询在输出中显示小写字符“S”:
SELECT LOWER( S );
输出结果为:
s
示例 5:此示例对 SQL 表使用 LOWER 函数
在此示例中,我们将创建一个新表,其字符串列将包含大写字符。
以下块中提到了创建新 SQL 表的语法:
CREATE TABLE table_name
(
First_Column_of_table Data Type (character_size of 1st Column),
Second_Column_of_table Data Type (character_size of the 2nd column ),
Third_Column_of_table Data Type (character_size of the 3rd column),
...
Last_Column_of_table Data Type (character_size of the Nth column)
);
以下 CREATE 语句创建Student_Marks表:
CREATE TABLE Student_Marks
(
Student_ID INT NOT NULL PRIMARY KEY,
Student_First_Name VARCHAR (100),
Student_Middle_Name VARCHAR (100),
Student_Last_Name VARCHAR (100),
Student_Class INT NOT NULL,
Student_City Varchar(120),
Student_State Varchar (80),
Student_Marks INT
);
下面的 INSERT 语句在Student_Marks表中插入大学学院的记录:
INSERT INTO Student_Marks (Student_ID, Student_First_Name, Student_Middle_Name, Student_Last_Name, Student_Class, Student_City, Student_State, Student_Marks) VALUES (4001, AMAN, ROY, SHARMA, 4, CHANDIGARH, PUNJAB, 88);
INSERT INTO Student_Marks
(Student_ID, Student_First_Name, Student_Middle_Name, Student_Last_Name, Student_Class, Student_City, Student_State, Student_Marks)
VALUES ( 4002, VISHAL, GURR, SHARMA, 8, MURTHAL, HARYANA, 95 );
INSERT INTO Student_Marks
(Student_ID, Student_First_Name, Student_Middle_Name, Student_Last_Name, Student_Class, Student_City, Student_State, Student_Marks)
VALUES (4007, RAJ, SINGHANIA, GUPTA, 6, GHAZIABAD, UTTAR PRADESH, 91);
INSERT INTO Student_Marks
(Student_ID, Student_First_Name, Student_Middle_Name Student_Last_Name, Student_Class, Student_City, Student_State, Student_Marks)
VALUES (4004, YASH, CHOPRA, SINGHANIA, 9, JAIPUR, RAJASTHAN, 85);
INSERT INTO Student_Marks
(Student_ID, Student_First_Name, Student_Middle_Name, Student_Last_Name, Student_Class, Student_City, Student_State, Student_Marks)
VALUES (4011, VINAY, SHARMA, ROY, 8, CHANDIGARH, PUNJAB, 94);
INSERT INTO Student_Marks
(Student_ID, Student_First_Name, Student_Middle_Name, Student_Last_Name, Student_Class, Student_City, Student_State, Student_Marks)
VALUES (4006, MANOJ, SINGHANIA, GUPTA, 5, GHAZIABAD, UTTAR PRADESH, 83);
INSERT INTO Student_Marks
(Student_ID, Student_First_Name, Student_Middle_Name, Student_Last_Name, Student_Class, Student_City, Student_State, Student_Marks)
VALUES (4010, RAM, RAHEEM, GUPTA, 9, LUCKNOW, UTTAR PRADESH, 89);
以下 SELECT 语句显示上述Student_Marks表的插入记录:
SELECT * FROM Student_Marks;
输出结果为:
Student_Id | Student_First_Name | Student_Middle_Name | Student_Last_Name | Student_Class | Student_City | Student_State | Student_Marks |
---|---|---|---|---|---|---|---|
4001 | AMAN | ROY | SHARMA | 4 | CHANDIGARH | PUNJAB | 88 |
4002 | VISHAL | GURR | SHARMA | 8 | MURTHAL | HARYANA | 95 |
4007 | RAJ | SINGHANIA | GUPTA | 6 | GHAZIABAD | UTTAR PRADESH | 91 |
4004 | YASH | CHOPRA | SINGHANIA | 9 | JAIPUR | RAJASTHAN | 85 |
4011 | VINAY | SHARMA | ROY | 8 | CHANDIGARH | PUNJAB | 94 |
4006 | MANOJ | SINGHANIA | GUPTA | 5 | GHAZIABAD | UTTAR PRADESH | 83 |
4010 | RAM | RAHEEM | GUPTA | 9 | LUCKNOW | UTTAR PRADESH | 89 |
以下 SELECT 查询将 LOWER 函数与上述 Student_Marks 表的 Student_Last_Name 列一起使用:
SELECT Student_Last_Name, LOWER(Student_Last_Name) AS LOWER_LastName FROM Student_Marks;
此 SQL 语句将上表中每个学生的姓氏转换为小写。
输出结果为:
Student_Last_Name | LOWER_LastName |
---|---|
SHARMA | sharma |
SHARMA | sharma |
GUPTA | gupta |
SINGHANIA | singhania |
ROY | roy |
GUPTA | gupta |
GUPTA | gupta |
以下 SELECT 查询将 LOWER 函数与上述 Student_Marks 表中 Student_Id 大于 4002 的学生的 Student_First_Name、Student_City 和 Student_State 列一起使用:
SELECT Student_Id, LOWER(Student_First_Name), LOWER(Student_City), LOWER(Student_State) FROM Student_Marks WHERE Student_Id >4002;
输出结果为:
Student_Id | LOWER(Student_First_Name) | LOWER(Student_City) | LOWER(Student_State) |
---|---|---|---|
4007 | raj | ghaziabad | uttar pradesh |
4004 | yash | jaipur | rajasthan |
4011 | vinay | chandigarh | punjab |
4006 | manoj | ghaziabad | uttar pradesh |
4010 | ram | lucknow | uttar pradesh |
热门文章
优秀文章