表里有shop1,shop2....shopn这样的n个字段,对于某条数据,这n个字段有的有值,有的为空,我想查询出所有数据对应的有值的字段,怎么做??

解决方案 »

  1.   

    select * from tab where shop1 is not null or shop2 is not null ....
      

  2.   

    不知道這個符合你的需求不?with tmp as
    (
    select 'yes' shop1, null shop2, 'yes' shop3 from dual
    union all
    select null shop1, null shop2, 'yes' shop3 from dual
    union all
    select null shop1, 'yes' shop2, null shop3 from dual
    )
    select regexp_replace(
               (trim('|' from
               decode(shop1, null, '', 'shop1') || '|' || 
               decode(shop2, null, '', 'shop2') || '|' || 
               decode(shop3, null, '', 'shop3')
               )), '[|]+', '|')
    from tmp;RESULT                                                                          
    -------------
    shop1|shop3                                                                     
    shop3                                                                           
    shop2     
      

  3.   

    用 not null 就可以了吧,不清楚你要达到什么效果