mysql 查询结果为空时值时执行后面的sql语句

sql server支持变量所以一般使用方法如下:

DECLARE @Val varchar(50)
select @Val = param_value where t_param where param_name = log_type
if(@Val is null)
begin
select @Val = param_default_value  where t_param_info where param_name = log_type
end
select @Val

 

mysql中执行语句时不支持定义变量及条件判断,所以想了个办法,也能达到相同目的

 

SELECT IFNULL(
(select param_value from t_param where param_name = log_type),
(select param_default_value from t_param_info where param_name = log_type)
) as param_value;

 

mysql 查询结果为空时值时执行后面的sql语句

上一篇:Oracle触发器13


下一篇:rpm 报错error: rpmdbNextIterator: skipping h# 231 Header V3 RSA/SHA1 Signature, key ID c105b9de: BAD