Oracle SQL 报告生成没有空值

Oracle SQL report generation without null

我的查询:

SELECT s.artist_id AS ArtistID,
       s.name AS Song,
       at.name AS artistname,
       a.name AS Albumname
  FROM album s
       LEFT OUTER JOIN song a ON s.id = a.album_id
       LEFT OUTER JOIN artist at ON at.id = s.artist_id;

歌曲和专辑中没有 table

对于加入 tables 后的上述查询,报告中为空 (演示结果)

实际结果

A B     
1 2                                                        
3 

预期结果

A B                                   
1 2                                                  
3 *  

我想在 excel 中打印上面的结果而不是 null 它应该被替换为任何字符。你能帮我怎么做吗?

一种选择是使用 NVL 函数,例如

nvl(a.name, '*') as albumname

或者,DECODE 可能有帮助:

decode(a.name, null, '*', a.name) as albumname

CASE:

case when a.name is null then '*'
     else a.name
end as albumname

ISO/ANSI 的标准函数是 COALESCE():

SELECT a.artist_id AS ArtistID,
       a.name AS Song,
       COALESCE(ar.name, '*') AS artistname,
       COALESCE(s.name, '*') AS Albumname
FROM album a LEFT OUTER JOIN
     song s
     ON a.id = d.album_id LEFT OUTER JOIN
     artist ar
     ON ar.id = a.artist_id;

请注意,我更改了 table 别名,因此它们是 table 名称的缩写。