mysql存储过程

创建存储过程

1.创建一个无参数的存储过程。

delimiter //               #mysql默认结束标志为分号,现在修改为两个斜杠。
create procedure pro_student()
begin
  delete from students;
end //
delimiter ;                #还原默认的结束标志。

2.创建一个有参数的存储过程。

delimiter //
create procedure pro_student(in sid int)
begin
  select * from students where id=sid;
end //
delimiter ;

3.创建一个带输出参数的存储过程 。

delimiter //
create procedure pro_student_count(out coun int)
begin
  select count(*) into coun from students;
end //
delimiter ;


call pro_student_count(@count);
select @count;


#结果:2

  

.调用存储过程。

#无参数调用方式:
call pro_student

#有参数调用方式:
call pro_student(1);

4.删除一个存储过程

drop procedure pro_student;

  

posted @ 2018-01-23 09:11  orna  阅读(154)  评论(0编辑  收藏  举报