要基于条件显示来自存储过程的消息,让我们使用IF-ELSE条件-
mysql> DELIMITER // mysql> CREATE PROCEDURE showMessage(value int,Name varchar(20)) BEGIN IF(value > 100) then SELECT CONCAT("HELLO"," ",Name); ELSE SELECT CONCAT("BYE"," ",Name); END IF; END // mysql> DELIMITER ;
情况1-当值大于100时,使用CALL命令调用存储过程-
call showMessage(200,'John');
这将产生以下输出-
+--------------------------+ | CONCAT("HELLO"," ",Name) | +--------------------------+ | HELLO John | +--------------------------+ 1 row in set (0.00 sec)
情况2-当值小于100时,将显示差异消息,因为将执行ELSE条件-
mysql> call showMessage(10,'John');
这将产生以下输出-
+------------------------+ | CONCAT("BYE"," ",Name) | +------------------------+ | BYE John | +------------------------+ 1 row in set (0.00 sec)