SQL UCASE函数

SQL UCASE函数

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

UCASE字符串函数的语法

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

SELECT UCASE(Column_Name) AS Alias_Name FROM Table_Name;

在这个语法中,Column_Name是该列的名称,其值将以大写字母显示。

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

SELECT UCASE(String);

Syntax2: 使用UCASE函数与各个小写字符配合的语法:

SELECT UCASE(lower_case_character);

UCASE字符串函数的示例

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

SELECT UCASE(javatpoint is a good website);

输出:

JAVATPOINT IS A GOOD WEBSITE

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

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

Example 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)
);  

以下是创建Faculty_Info表的CREATE语句:

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查询使用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查询在上面的Faculty_Info表中使用UCASE函数与Faculty_Last_Name和Faculty_Address列,查询工资大于30000的教职员工的相关信息:

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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程