存储过程语法
设置变量: set @dogNum = 1002;
1、无参的存储过程
delimiter $
CREATE PROCEDURE 存储过程名()
begin
存储过程体
end $;
2、有参数的存储过程
delimiter $
CREATE PROCEDURE 存储过程名(in|out|inout 参数名1 参数类型,参数名2 参数类型……)
begin
存储过程体
end $;
3、删除存储过程:
DROP PROCEDURE IF EXISTS 存储过程名
;
4、创建调用查询存储
drop PROCEDURE if EXISTS PRO_TEST
delimiter $
create PROCEDURE PRO_TEST()
BEGIN
select name from test WHERE name = "xiaoli";
end $
call PRO_TEST 调用
show PROCEDURE STATUS 查询存储过程
drop PROCEDURE PRO_TEST 删除存储过程
有参数的存储过程
DROP PROCEDURE IF EXISTS `test`;
delimiter $
CREATE PROCEDURE test(in dogNum int(10))
begin
select d.dog_num ,d.dog_name ,d.dog_kind ,d.dog_age
from dog d where d.dog_num =dogNum;
end $
call test(1001);
带有输出参数
DROP PROCEDURE IF EXISTS `sp_test_out`;
delimiter $
CREATE PROCEDURE sp_test_out(out col_test varchar(20))
begin
select 'test' into col_test from dual;
end $;
call sp_test_out(@col_test);
select @col_test;