如何抑制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)
热门推荐
2 祝福语简短七夕
6 薛之谦祝福语简短
10 朋友祝福语两字简短
11 表达家人的祝福语简短
12 生日祝福语简短明了 同事
13 升学祝福语简短的个性
14 新老师祝福语 简短独特
15 新婚抖音祝福语简短
16 朋友搬迁新房祝福语简短
17 关云生字祝福语简短
18 迟到的过年祝福语简短