8

我想做类似的事情:

select (if lookup = 8 then 08 else lookup) lookup
  , //more columns
from lookup_table
order by lookup

不幸的是,Oracle 似乎不喜欢这种语法,我无法发现原因或找到我应该使用的其他函数。

基本上,如果lookup值为8,我想得到08,否则我想要lookup的值。我敢肯定我只是愚蠢。

4

1 回答 1

15

你想要一个案例陈述:

select (case when lookup = 8 then 8 else lookup end) as lookup

如果lookup是一个字符串,你可能想要:

select (case when lookup = '08' then '08' else lookup end) as lookup

如果lookup是一个整数,并且您想将其转换为字符串,则:

select (case when lookup = 8 then to_char(lookup, '00') else to_char(lookup, '00') end) as lookup

但是,这对我来说似乎是多余的。

于 2013-03-27T17:18:07.130 回答