我有一个有null的表:
STREET_NAME | LOCATION | CULVERT_TYPE | CULVERT_WIDTH | CULVERT_MATERIAL | |
---|---|---|---|---|---|
主ST | 从ST A到ST B | 下水道风暴涵洞 | 1750 | 波纹钢管 | |
侧ST | 从ST C到ST D | 下水道风暴涵洞 | 波纹钢管 | ||
竞技场1 | 下水道风暴涵 | 300 | |||
下水道风暴涵 | 500 | ||||
。 |
使用case .. when
如下:
Select
Trim('|' from
case when street_name is not null then street_name end
|| case when location is not null then '|' || location end
|| case when culvert_type is not null then '|' || culvert_type end
|| case when culvert_width is not null then '|' || culvert_width end
|| case when culvert_material is not null then '|' || culvert_material end)
From your_table;
您也可以使用regexp_replace
和trim
如下:
Select
Trim('|' from
regexp_replace( street_name || '|' || location || '|' ||
culvert_type || '|' ||
culvert_width || '|' || culvert_material ,'[|]+','|'))
From your_table;