如何抑制MySQL存储过程的输出?
要取消MySQL存储过程的输出,可以使用变量。让我们首先创建一个表。
mysql> create table person_information -> ( -> Id int, -> Name varchar(20) -> );
以下是使用insert命令在表中插入一些记录的查询:
mysql> insert into person_information values(100,'John'); mysql> insert into person_information values(101,'Chris'); mysql> insert into person_information values(102,'Robert');
以下是使用select命令显示表中记录的查询:
mysql> select *from person_information;
这将产生以下输出
+------+--------+ | Id | Name | +------+--------+ | 100 | John | | 101 | Chris | | 102 | Robert | +------+--------+ 3 rows in set (0.00 sec)
这是禁止显示MySQL存储过程输出的查询:
mysql> DELIMITER // mysql> CREATE PROCEDURE sp_supressOutputDemo() -> BEGIN -> set @output=(select Name from person_information where id=101); -> END -> // mysql> DELIMITER ;
您可以使用CALL命令调用上述存储过程:
mysql> call sp_supressOutputDemo();
调用上述存储过程后,我们什么也没得到。因此,您需要使用select语句来获取输出。
以下是查询
mysql> select @output;
这将产生以下输出
+---------+ | @output | +---------+ | Chris | +---------+ 1 row in set (0.00 sec)
热门推荐
10 师傅退休蛋糕祝福语简短
11 生日祝福语 简短独特高考
12 圣诞祝福语简短小学
13 买房的祝福语高级简短
14 爱情祝福语大全 简短实际
15 俄语祝福语贺卡文案简短
16 英文祝福语简短带名字
17 周末祝福语正能量简短
18 简短霸气的考试祝福语