检查MySQL存储过程中的NULL或空变量
要检查NULL或空变量,请使用IF条件。让我们创建一个存储过程-
delimiter //
create procedure checkingForNullDemo(Name varchar(20))
begin
if Name is NULL OR Name='' then
select 'Adam Smith';
else
select Name;
end if ;
end
//
delimiter ;情况1
传递NULL时。使用调用命令调用存储过程
call checkingForNullDemo(NULL);
这将产生以下输出-
+------------+ | Adam Smith | +------------+ | Adam Smith | +------------+ 1 row in set (0.00 sec)
情况二
传递值时。使用call命令调用存储过程
call checkingForNullDemo('John Doe');这将产生以下输出-
+----------+ | Name | +----------+ | John Doe | +----------+ 1 row in set (0.00 sec)
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短