如何抑制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 婶婶拜年祝福语大全简短