第一部分:样例库的应用
1)字符串类(文本处理函数)
语句:
select cust_name,cust_contact
from customers
where SOUNDEX(cust_contact)=SOUNDEX(‘Y Lie’);
截图:
2) 数值类型(数值处理函数)
语句:
select round(1.23);
截图:
3)日期类型(日期和时间处理函数)
语句:
select cust_id,order_num from orders
where order_date=‘2005-09-01’;
截图:
4)数据类型转换函数
语句:
SELECT CAST(1995 AS CHAR) as result
截图:
5)条件控制函数
语句:
select case DAYOFWEEK(now())
when 1 then ‘星期日’
when 2 then ‘星期一’
when 3 then ‘星期二’
when 4 then ‘星期三’
when 5 then ‘星期四’
when 6 then ‘星期五’
else ‘星期六’ end as week,
DAYNAME(now()),
DAYOFWEEK(now());
截图:
6)系统信息函数
语句:
select VERSION();
截图:
7)用户自定义函数(补充)
语句:
CREATE FUNCTION zidingyi() returns int
begin
DECLARE num int DEFAULT 0;
select count() into num
from customers;
return num;
end
SELECT zidingyi();
第二部分:所选课题数据库的应用
1)字符串类(文本处理函数)
语句:
select cert,name
from movieexec
where SOUNDEX(name)=SOUNDEX(‘Merv Griffin’);
截图:
2) 数值类型(数值处理函数)
语句:
select round(4.28);
截图:
3)日期类型(日期和时间处理函数)
语句:
select name,birthdate from moviestar
where birthdate=‘1977-06-07’;
截图:
4)数据类型转换函数
语句:
SELECT CAST(2552 AS CHAR) as result
截图:
5)条件控制函数
语句:
select case DAYOFWEEK(now())
when 1 then ‘星期日’
when 2 then ‘星期一’
when 3 then ‘星期二’
when 4 then ‘星期三’
when 5 then ‘星期四’
when 6 then ‘星期五’
else ‘星期六’ end as week,
DAYNAME(now()),
DAYOFWEEK(now());
截图:
6)系统信息函数
语句:
select CONNECTION_ID();
截图:
7)用户自定义函数(补充)
语句:
CREATE FUNCTION zidingyi2() returns int
begin
DECLARE num2 int DEFAULT 0;
select count() into num2
from moviestar;
return num2;
end
SELECT zidingyi2();
数据库系统实训——实验九——函数
最新推荐文章于 2024-05-31 17:54:24 发布