如何抑制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 教师闺蜜祝福语简短