-2
ADRLN1                                   ADRLN2                                   ADRLN3                                   ADRLN4                                   ADRCIT                    ADRSTA                    ADRCNY                    ADDRESS
---------------------------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ------------------------- ------------------------- ------------------------- ----------
Tsrdl                                    address1                                 address2                                  dfdfdfdfdfdfdfdfdfdfdfdfdf              Alibaug                   Maharashtra               India                     412001
aaa aa Ltd.                              Mahalaxmi                                                                                                                  Mumbai                    Maharashtra                                         400011
190, SANDESH VIHAR (P&T)                 DELHI                                                                                                                                                                                                    110034
6/2/A LLOYDS GARDEN                      APPASAHEB MARATHE MARG                   PRABHADEVI                               MUMBAI                                                                                                                 400025

以上数据是使用select查询从数据库中反映出来的

输出:

ADRLN1                                   ADRLN2                                   ADRLN3                                   ADRLN4                                   ADRCIT                    ADRSTA                    ADRCNY                    ADDRESS
---------------------------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ------------------------- ------------------------- ------------------------- ----------
Tsrdl                                    address1                                 address2                                  dfdfdfdfdfdfdfdfdfdfdfdfdf              Alibaug                   Maharashtra               India                     412001
aaa aa Ltd.                              Mahalaxmi                                Mumbai                                    Maharashtra                             400011
190, SANDESH VIHAR (P&T)                 DELHI                                    110034
6/2/A LLOYDS GARDEN                      APPASAHEB MARATHE MARG                   PRABHADEVI                               MUMBAI                                   400025

我需要以下方式的输出。假设如果任何一列是空白的,那么它应该被下一列值替换。

4

1 回答 1

1

你应该使用合并。例如,

select coalesce (ADRLN1, ADRLN2, ADRLN3, ADRLN4 ) as ADRLN1 
  coalesce (ADRLN2, ADRLN3, ADRLN4 ) as ADRLN2,
  coalesce (ADRLN3, ADRLN4 ) as ADRLN3,
  ADRLN2 as ADRLN2
from table;

但是您应该继续使用逻辑来真正改变您的专栏。

编辑:似乎您想消除地址中的“空白”。

您可以做的一个技巧是选择列的串联:

select decode(ADRLN3, null, null, ADRLN3||',')||
   decode(ADRLN4, null, null, ADRLN4||',')||
   decode(ADRCIT, null, null, ADRCIT||',')||
   decode(ADRSTA, null, null, ADRSTA||',')||
   decode(ADRCNY, null, null, ADRCNY||',')||
   ADDRESS  as ADDRESS
from table;
于 2013-02-28T12:53:37.827 回答