存储过程
创建:
create procedure 存储过程名称([参数列表])
begin
---SQL语句
end;
调用
xxxxxxxxxx
call 名称([参数]);
查看
select * from information_schema.routines where routine_schema = 'xxx';#查询指定数据库的存储过程及状态信息
show create procedure 存储过程名称;#查询某个存储过程的定义
删除
drop procedure [if exists] 存储过程名称;
注意:在命令行进行演示时,执行创建存储过程的SQL时,需要通过关键字delimiter来指定SQL语句的结束符
delimiter $$
上面那行表示此时命令的结束不是以默认的分号为准,而是只有当出现$$,才会结束一段完整的命令,就可以在命令行输入如下:
create procedure p1()
begin
select count(*) from student;
end$$
以后我们每个命令的结束符就不是分号了,而是$$。如果要改回来的话,输入如下即可
xxxxxxxxxx
delimiter ;