我确定这是一个简单的选择。Oracle有条件选择
我该如何做一个列上的条件值选择。
Basically if column1 ='Y' then display as "FOO" else if 'n' display "foobar"
select column1 from table1;
我确定这是一个简单的选择。Oracle有条件选择
我该如何做一个列上的条件值选择。
Basically if column1 ='Y' then display as "FOO" else if 'n' display "foobar"
select column1 from table1;
select case column1 when 'Y' then 'FOO' else 'foorbar' end
from table1;
即假设一个简单的if/else。你的问题指定了两个值,并且可以同时检查:
select case column1 when 'Y' then 'FOO' when 'n' then 'foorbar' end
from table1;
如果您有其他Y
任何column1
价值观和n
你会得到null
;你还可以指定一个else
不同的值,即使你超过一个明确的值测试:
select case column1 when 'Y' then 'FOO' when 'n' then 'foorbar' else 'bar' end
from table1;
感谢我的朋友......... –
在甲骨文的替代语法是解码,我喜欢这个,因为它的漂亮,简洁,但基本上不相同的情况下声明上面建议:
select decode(column1,'Y','FOO','foobar') from table1;
的语法如下:解码(表达,搜索,导致[,搜索,结果] ... [默认])。
进一步的例子是在甲骨文的文档:http://www.techonthenet.com/oracle/functions/decode.php
我忘了解码...这对布尔值工作很好... –
这不是PL/SQL,它是普通的SQL,虽然甲骨文味。你也可以在PL/SQL中使用'case',但是作为select的一部分并不真正相关。 –