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);
语法2: 这个语法使用LOWER函数与单个大写字母字符:
SELECT LOWER(upper_case_character);
低级字符串函数示例
示例1: 以下SELECT查询将以下字符串的所有字符转换为小写:
SELECT LOWER(JAVATPOINT IS A GOOD WEBSITE);
输出:
javatpoint is a good website
例子2: 由于LOWER函数无法改变SQL中字符串的符号和整数,因此以下SELECT查询无法改变以下字符串的字符。
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:此示例使用LOWER函数与SQL表
在此示例中,我们将创建一个新表,其字符串列将包含大写字符。
创建新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
);
以下是将college Faculties的记录插入到 Student_Marks 表中的INSERT查询语句:
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 |