您的位置:首页 > 数据库 > MySQL

mysql自定义函数

2016-06-10 13:10 716 查看
//注意规避mysql关键字,可能需要重定义结束符号符delimiter $$
//声明函数:参数类型以及返回类型
create function insertY(start int(11),end int(11))
returns varchar(255)
//开始函数实现
begin
//定义一个变量
declare i int(11);
//给变量赋值,需要加set
set i = start;
//while condition do,end while
while i <= end do
//if condition then,else,end if
//注意比较是否相等使用 = 而不是 ==
if (i mod 2 = 0) then
insert into A values(i);
else
insert into B values(i);
end if;
insert into C values(i);
set i = i + 1;
end while;
return "finished";
end


//创建一个查询过程

create procedure sq(qq_ varchar(15))
begin
select * from T_qq_9 where qq = qq_ union
select * from T_qq_10 where qq = qq_ union
select * from T_qq_5 where qq = qq_ union
select * from T_qq_6 where qq = qq_ union
select * from T_qq_7 where qq = qq_ union
select * from T_qq_8 where qq = qq_;
end

call sq("343234223");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql 函数