您的位置:首页 > 博客中心 > 数据库 >

MySQL存储过程中判断形参是否为空null

时间:2022-03-14 08:37

直接看例子:

DELIMITER $$
CREATE DEFINER=`root`@`127.0.0.1` PROCEDURE `restore`(username varchar(50))
BEGIN
if username is not null then
    update user set invalid=0 and activate_time=‘0000-00-00 00:00:00‘ where `name`=username;
else
    update user set invalid=0 and activate_time=‘0000-00-00 00:00:00‘;
end if;
END$$
DELIMITER ;

调用:

1. call restore(‘abc‘);

   or call restore(null);

 

本类排行

今日推荐

热门手游