Home » MySQL » MySQL-存储过程

MySQL-存储过程

编 辑:Y ┊ 时 间:2018年10月09日 ┊ 访问: 76 次
#这是一个表
create table t_courses(
`id` int(11) not null auto_increment primary key,
`name` varchar(20) not null,
`score` int(4) not NULL default 0,
`userid` varchar(32) NOT NULL
)CHARSET=utf8;

#创建一个用户表 t_persons
create table t_persons(
`id` int(11) not null auto_increment primary key,
`name` varchar(30) not null,
`age` int(3) not null default 0,
`height` int(3) not null default 0,
`weight` int(3) not null default 0
)CHARSET=UTF8;

调用无参存储过程
call procedureName();

调用含有in类型有参存储过程

set @variableName=variableValue;
call procedureName(@variableName);

调用含有out类型的参数存储过程

set @variableName=defaultValue;
call procedureName(@variableName);

删除
drop procedure procedureName;

循环体loop
in out参数

delimiter //
create procedure p_person()
begin
select * from t_persons;
end
//

调用

call p_person();

删除

drop procedure p_person;

带有in参数

delimiter //
create procedure p_person(in myid int)
begin
select * from t_persons where id=myid;
end
//

set @myid=1;
call p_person(@myid);
delimiter //
create procedure p_person(out myName varchar(20), in myid bigint)
begin
select name into myName from t_persons where id = myid;
end
//

set @myName='';
call p_person(@myName,2);
select @myName;

存储过程.txt




Copyright © 2026 Y 版权所有.网站运行:13年238天21小时25分