我要实现一个动态的视图.原表结构是这样的.批号  F1 F2 F3 F4 F5 F6, F1-F6是NUMBER.在实际的业务中,F1-F6不可能同时出现,最多只有其中四种出现.
那现在就要生成一个视图,把其中出现的列出,不出现的字段就不出列出来.

批号  F1 F2 F3 F4 F5 F6,
AAAA  
BBBB         1
CCCC
DDDD              4
EEEE                  4
那么,F1,F2与F4   没有出现,我就要生成如下的视图
批号  F3 as f1 F5 as f2 F6 as f3
再如:
批号  F1 F2 F3 F4 F5 F6,
AAAA  2
BBBB      4  1
CCCC
DDDD              4   
EEEE                  
那么,F4,F6   没有出现,我就要生成如下的视图批号  F1 as f1 F2 as f3 F3 as f3,F5 as f4生成的视图,后面的字段总是f1-f4,不变的.只是内容在变成.

解决方案 »

  1.   

    当然,如果字段是动态的也行.即生成,
    批号  F1 , F2 ,F3,F5 

    批号  F3 , F5 ,F6也行,我作处理一下,也能用了.谢大哥们帮帮忙呀!比较急. 
      

  2.   

    select substr(f,1,1) f1,substr(f,2,1) f2,substr(f,3,1) f3,substr(f,4,1) f4
    from
    (
    select
    decode((select count(*) from tab where f1 is not null),0,'',nvl(trim(to_string(f1)),' '))||
    f2~f15//按照f1的例子把f2~f15之间的语句补齐了
    ||decode((select count(*) from tab where f16 is not null),0,'',nvl(trim(to_string(f16)),' ')) f
    from tab
    );我没测试,看明白思路就知道怎么写了
      

  3.   

    select f,substr(f,1,6) f1,substr(f,7,6) f2,substr(f,13,6) f3,substr(f,19,6) f4
    from
    (
    select
    decode((select count(*) from trsc_bzsjd t where t.fail1 is not null and t.fail1<>0 ),0,'',nvl(trim(to_char(t.fail1,'000000')),''))||
    decode((select count(*) from trsc_bzsjd t where t.fail2 is not null and t.fail2<>0  ),0,'',nvl(trim(to_char(t.fail2,'000000')),''))||
    decode((select count(*) from trsc_bzsjd t where t.o_s is not null and t.o_s<>0  ),0,'',nvl(trim(to_char(t.o_s,'000000')),''))||
    decode((select count(*) from trsc_bzsjd t where t.fail1_eas is not null and t.fail1_eas<>0  ),0,'',nvl(trim(to_char(t.fail1_eas,'000000')),''))||
    decode((select count(*) from trsc_bzsjd t where t.fail1_f1 is not null and t.fail1_f1<>0  ),0,'',nvl(trim(to_char(t.fail1_f1,'000000')),''))||
    decode((select count(*) from trsc_bzsjd t where t.fail1_f2 is not null and t.fail1_f2<>0  ),0,'',nvl(trim(to_char(t.fail1_f2,'000000')),'')) ffrom trsc_bzsjd t);成功了.谢谢帮忙呀!