4、MySql的存储过程
C:\Program Files\MySQL\MySQL Server 5.1\bin
1.1 定义无参数的存储过程
//定义语句结束用//
delimiter //
create procedure proc_teacher_noparam()
begin
select * from teacher;
end
//
//定义语句结束用;
delimiter ;
1.2.调用无参数的存储过程
call proc_teacher_noparam();
2.1 定义输入参数的存储过程
//定义语句结束用//
delimiter //
create procedure proc_teacher_inparam(in n int)
begin
select * from teacher where id=n;
end
//
//定义语句结束用;
delimiter ;
2.2.调用输入参数的存储过程
//定义变量
set @n=1;
//调用存储过程
call proc_teacher_inparam(@n);
3.1 定义有输出参数的存储过程
drop procedure if exists proc_teacher_outparam;
delimiter //
create procedure proc_teacher_outparam(out n int)
begin
select count(*) into n from teacher;
end
//
delimiter ;
//3.2 调用输出参数的存储过程
set @n=1;
call proc_teacher_outparam(@n);
select @n;
//4.定义有输入和输出参数的存储过程
delimiter //
drop procedure if exists proc_teacher_in_outparam;
create procedure proc_teacher_in_outparam(in n int,out o int)
begin
select count(*) into o from teacher where id=n;
end
//
delimiter ;
//4.2 调用带有输入和输出参数的存储过程
sex @n=1;
call proc_teacher_inoutparam(1,@n);
select @n;
//5.1 创建输入输出参数是同一个变量的存储过程
delimiter //
drop procedure if exists proc_teacher_inoutparam;
create procedure proc_teacher_inoutparam(inout n int)
begin
select count(*) into n from teacher where id=n;
end
//
delimiter ;
//5.2 调用输入输出参数是同一个变量的存储过程
sex @n=1;
call proc_teacher_inoutparam(@n);
select @n;