1、创建存储过程
create procedure mypl()
begin
insert into 表名(字段) values(值)
end $
调用 call mypl() $
2、创建带in模式参数的存储过程(根据in输入字段筛选)
create procedure mypl(in name varchar(20))
begin
select * from 表名 left join * on * = *
where * = name;
end $
call mypl(' ')
使用存储过程查看用户是否登录成功
create procedure login(in username varchar(20),in password varchar(20))
begin
declare result varchar(20) default ' ',#声明并初始化
select count(*) into result #赋值
from admin
where admin.username = username
and admin.password = password;
select if(result > 0,'成功','失败');#使用
end $
call login('name','password')
4、创建带out模式的存储过程(输出查询结果)
create procedure mypl(in * ,out name)
begin
select name into name from table left join * = * where * = *;
end $
#调用
set @bName$
call mypl(' ',@bName)$
select @bName$
create procedure mypl(in ,out name1,out name2)
begin
select name1,name2 into name1,name2 from table left join * = * where * = *;
end $
call mypl('',@name1,@name2)
创建inout模式参数存储过程
create procedure mypl(inout a,inout b)
begin
set a = a * 2;
set b = b *2;
end $
set @m = 10$
set @n = 20$
call mypl(@n,@m)$
select @m,@n$
网友评论