首页 > 数据库技术 > 详细

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

时间:2020-05-26 23:02:09      阅读:102      评论:0      收藏:0      [点我收藏+]

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语句

原文:https://www.cnblogs.com/dcrenl/p/12968487.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!