如何抑制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 生日广州男生祝福语简短