Concatenate columns and some with NULL value

2

I'm doing a select and concatenating the columns, when a column has value NULL (has no value) the entire line gets NULL follows an example:

select 'teste'||CONTROLE||','||CODIGO||','||DATA||','||HISTORICO from tabela

The results:

null
null
null
null
teste05,06501,2015-08-01,maria
null
null
null
teste09,01123,2015-08-01,ronaldo
null
null
null
teste13,07361,2015-08-01,tenório

It is known that only the last column can have value null , so I wanted the result to be in the first line as shown below:

teste01,06501,2015-08-01,
teste02,07052,2015-08-01,
teste03,03574,2015-08-01,
teste04,04123,2015-08-01,
teste05,06501,2015-08-01,maria
teste06,...
teste07,...
teste08,...
teste09,01123,2015-08-01,ronaldo
teste10,...
teste11,...
teste12,...
teste13,07361,2015-08-01,tenório

The above example I can not get, I just wrote in the same hand to show what I expected as a result because even if all the columns were NULL yet I wanted a result with which I concatenei ex: teste,,, if everything was null .

I've tried to use if , tried a case and nothing. Ma documentation just found something that does not fit this case.

    
asked by anonymous 13.08.2015 / 15:47

1 answer

4

You must use the COALESCE(coluna, '')

    
13.08.2015 / 15:59