创建存储过程
DELIMITER $$ --定义分割符
DROP PROCEDURE IF EXISTS getRecord $$
CREATE PROCEDURE getRecord (
IN in_id INTEGER, --定义输入参数
OUT out_name VARCHAR(20), --输出参数
OUT out_age INTEGER) ---输出参数
BEGIN
SELECT name, age
INTO out_name, out_age
FROM Student where id = in_id;
END $$
DELIMITER ;
调用存储过程:
--调用存储过程
mysql> call getRecord(10,@name,@age);
Query OK, 1 row affected (0.51 sec)
--查询输出参数
mysql> select @name,@age;
+-----------+------+
| @name | @age |
+-----------+------+
| 张胜男 | 22 |
+-----------+------+
1 row in set (0.02 sec)
实例:
drop PROCEDURE IF EXISTS getResult;
create PROCEDURE getResult(
in in_id INTEGER,
out out_data VARCHAR(20)
)
BEGIN
#DECLARE total INTEGER;
DECLARE return_msg VARCHAR(30);
SELECT * FROM login WHERE id=in_id;
SELECT CONCAT('数据统计为:',count(1)) INTO out_data FROM login WHERE id=in_id ;
#SET return_msg = CONCAT('数据统计为:',total);
#select return_msg into out_data;
END;
call getResult(1,@data);
select @data;
参考:
https://blog.csdn.net/lizzyshao/article/details/83585328
https://blog.csdn.net/u012326462/article/details/83445404