Hive concat connection function after the result is null

Hive concat connection function after the result is null

concat function is used to connect a string

Example of use:

select concat('Hello','World','Java');

operation result:

 

Recently, we used to do when demand concat to splice the address information, the script is as follows: (ta is my store address information table aliases, addresses divided into three sections storage)

concat(trim(ta.houseaddress),' ',trim((ta.houseaddress2),' ',trim(ta.houseaddress3))

In general, we think this will be no problem, meaning that removing the spaces before and after each part of the address, then use the space between each piece of mosaic.

But when we tested it finds a problem yeah, there are a lot of address information is not empty of data becomes empty ....

 

Start looking for reasons:

Concat function is found in a null value when the connector entire result will be set to null

E.g: 

select concat('Hello','World','Java',null);

Results of the:

 

Address connection information script after correction:

concat(trim(nvl(ta.houseaddress,'')),' ',trim(nvl(ta.houseaddress2,'')),' ',trim(nvl(ta.houseaddress3,'')))

Guess you like

Origin www.cnblogs.com/DFX339/p/11841126.html