做个题就会的知识,mysql⾃定义函数例题及答案(三)我会连续⽤⼀两个表,陆续出⼀些题⽬,同时也会给出答案,题⽬⼀般含有视图触发器,函数,存储过程
⾃定义函数例题:
还是那个富豪榜,有id、姓名、年龄、⾝价
mysql面试题目及答案当你需要插⼊⼀个富豪信息时
往函数中传参,传⼊他的个⼈信息,之后
你需要知道和他⾝价相等的富豪总数是多少⼈
企业管理系统
语法:
create function函数名([参数列表])returns数据类型
begin
sql语句;#也可以写逻辑语句
return值;
end;
如果不了解语法的含义,看我的另⼀篇⽂章:
答案:
尽量⾃⼰做下^_^
创建富豪表
create table wealthy(
id int primary key auto_increment,
age int,
name varchar(20),
money int);
插⼊需要的数据
filecopy用法
insert into wealthy values(1,20,'张三',110);
insert into wealthy values(2,35,'李四',110);
insert into wealthy values(3,35,'王五',90);
insert into wealthy values(4,20,'赵六',90);
创建平民表
create table person(
id int primary key auto_increment,
age int,
name varchar(20),
money int);
aspnet网站模板下载插⼊需要的数据
insert into person values(0,20,'⼗⼀',30);
创建函数,变量的定义要放在前⾯
delimiter $$
create function num(names varchar(20),ages int,moneys int)returns int begin
declare n int default0;
insert into wealthy values(0,ages,names,moneys);
select count(*)into n from wealthy where money=moneys;
set n= n-1;
return n;
end;
$$
delimiter;
调⽤函数
select num('⼗⼆',29,110);
查看函数
show create function num \G;
premium access是什么软件>绿山墙的安妮美剧show function status like'num'\G;#在所有函数中模糊查询
删除函数
drop function num;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。