0

My query:

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;

null in song and album table

for above query after joining the tables there is null in report (demo result)

Actual result

A B     
1 2                                                        
3 

Expected result

A B                                   
1 2                                                  
3 *  

I want to print the above result in excel instead of null it should be replaced with any character. Could you pls help me how to do it?

2 Answers 2

2

The ISO/ANSI standard function for this is 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;

Notice that I changed the table aliases so they are abbreviations for the table names.

Sign up to request clarification or add additional context in comments.

Comments

0

One option is to use the NVL function, e.g.

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

Or, DECODE might help:

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

Or CASE:

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

1 Comment

"The ISO/ANSI standard function for this is COALESCE():"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.