mysql:if语句在n行中查找空列

jaql4c8m  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(351)

我试图使用if语句来找出 primary key = copy_code 有一列 return = null 如果是的话,我想做点什么。

IF ((SELECT `return` FROM loan
       WHERE `code` = copy_code AND `return` IS NULL) IS NULL THEN
          do something
   END IF;

我没有得到任何错误,但当我插入数据时,我没有得到正确的结果。
我怎样才能做到这一点?

vhmi4jdf

vhmi4jdf1#

set delimiter //
create procedure foo as 
begin
declare @variable int

 SELECT count(*) INTO @variable FROM loan
 WHERE `code` = copy_code AND `return` IS NULL;

 if (@variable) 
 begin
   ... do something
 end
end//
set delimiter ;

相关问题