我知道合并将返回传递给它的第一个非空值。是否有类似的东西会返回第一个非空/非假值?
例子:
select FunctionIWant(0,'','banana') as fruit; //returns banana.
使用ANSI CASE语句/表达式:
SELECT CASE WHEN LENGTH(col) = 0 OR col IS NULL THEN 'banana' ELSE col END AS fruit
SQL或MySQL中没有布尔值。MySQL实际上将该值存储为INT,值为零或一:
SELECT CASE WHEN col = 0 THEN 'banana' ELSE col END AS fruit