根据documentation 案例陈述:
CASE语句评估单个表达式并将其与几个潜在值进行比较
看来我可以在case语句中将表达式放在一个数字上,例如A + B
,但是我不能把表达式计算为布尔值,例如A = B
。我被迫将表达式放在when子句中。我希望Oracle将TRUE和FALSE视为1和0,并对它们应用相同的规则。
为什么这无效?
布尔表达式不执行
-- boolean expression in case statement compared to 1 and 0
select case a = b
when 1 then
'EQUAL'
else
'NOT EQUAL'
end as _RESULT
from dual;
--boolean expression in case statement compared to TRUE and FALSE
select case a = b
when TRUE then
'EQUAL'
else
'NOT EQUAL'
end as _RESULT
from dual;
数字表达式执行
--numeric expression in case statement compared to the number 3
select case a + b
when 3 then
'THREE'
else
'NOT THREE'
end as _RESULT
from dual;
当执行子句时的布尔表达式
select case
when a = b then
'EQUAL'
else
'NOT EQUAL'
end as _RESULT
from dual;