在oracle中显示带解码功能的数据

时间:2012-11-08 08:02:15

标签: oracle concatenation decode

原始数据(图片) enter image description here 我想通过连接几个列来显示我的数据。但是看起来不完美的数据:在连接结束时有一个逗号,如图所示:

http://i1207.photobucket.com/albums/bb476/daniwarrior/decode1.jpg

这是我在oracle 10g中创建的查询

    select id_pegawai, 
    whitelist_pembayaran||decode(whitelist_pembayaran,null,null,', ')||
    whitelist_pemasang||decode(whitelist_pemasang,null,null,', ')||
    whitelist_jenis_iklan||decode(whitelist_jenis_iklan,null,null) as whitelist,

    blacklist_pembayaran||decode(blacklist_pembayaran,null,null,', ')||
    blacklist_pemasang||decode(blacklist_pemasang,null,null,', ')||
    blacklist_jenis_iklan||decode(blacklist_jenis_iklan,null,null) as blacklist
    from verifikator order by id_verifikator desc

1 个答案:

答案 0 :(得分:2)

所以你只想删除最后的逗号? RTRIM它。

select id_pegawai,
       rtrim(whitelist_pembayaran || decode(whitelist_pembayaran, null, null, ', ') ||
              whitelist_pemasang || decode(whitelist_pemasang, null, null, ', ') ||
              whitelist_jenis_iklan, ',') as whitelist,

       rtrim(blacklist_pembayaran || decode(blacklist_pembayaran, null, null, ', ') ||
              blacklist_pemasang || decode(blacklist_pemasang, null, null, ', ') ||
              blacklist_jenis_iklan, ',') as blacklist
  from verifikator
 order by id_verifikator desc