mysql数据库中 if(v1, v2, v3) 函数作用为非空判断,等效于 oracle 库中的 nvl2 函数,当v1不为空返回值为v2,v1为空返回值为v3,请看例子:
mysql
select if(now(),'b','c') as result from dual;
-- 查询结果为:b
select if(null,'b','c') as result from dual;
-- 查询结果为:c
oracle
select nvl2(sysdate,'b','c') as result from dual;
-- 查询结果为:b
select nvl2(null,'b','c') as result from dual;
-- 查询结果为:c
网友评论