基本用法
建立表 user
1 . 创建
CREATE procedure getUserName()
BEGIN
SELECT * from user;
end;
2 . 调用
CALL getUserName();
3 . 删除
drop PROCEDURE if EXISTS getUserName; //没有()
参数
1 . out
//out参数,从存储过程中传出
CREATE procedure getUserName(
out uName VARCHAR(20)
)
BEGIN
SELECT `user`.username into uName from user where `user`.id = 1;
end;
CALL getUserName(@uName);
SELECT @uName;
2 . in
drop PROCEDURE if EXISTS getUserName;
CREATE procedure getUserName(
in userId int
)
BEGIN
SELECT * from user where `user`.id = userId;
end;
CALL getUserName(1);