select decode(t.A, null, decode(t.B, null, t.C, t.B), t.A) as newA from tab1 t
WITH T AS ( SELECT '1' a,'' b,'' c FROM dual UNION ALL SELECT '','3','' FROM dual UNION ALL SELECT '','4','' FROM dual UNION ALL SELECT '','5','' FROM dual UNION ALL SELECT '','','2' FROM dual ) SELECT nvl(nvl(a,b),c) FROM t--result: 1 3 4 5 2
什么叫要一个新列?改表结构增加新列么? with tablea as ( select '1' A, '' B, '' c from dual union all select '' a, '3' b, '' c from dual union all select '' A, '4' B, '' c from dual union all select '' a, '' b, '5' c from dual ) select (case when a is not null then a when b is not null then b when c is not null then c end ) d from tablea
select decode(t.A,
null,
decode(t.B, null, t.C, t.B),
t.A) as newA from tab1 t
(
SELECT '1' a,'' b,'' c FROM dual
UNION ALL
SELECT '','3','' FROM dual
UNION ALL
SELECT '','4','' FROM dual
UNION ALL
SELECT '','5','' FROM dual
UNION ALL
SELECT '','','2' FROM dual
)
SELECT nvl(nvl(a,b),c) FROM t--result:
1
3
4
5
2
with tablea as ( select '1' A, '' B, '' c from dual
union all
select '' a, '3' b, '' c from dual
union all
select '' A, '4' B, '' c from dual
union all
select '' a, '' b, '5' c from dual )
select (case when a is not null then a
when b is not null then b
when c is not null then c end ) d from tablea
用case when 我也没整明白
select ifnull(ifnull(a,b),c) from t