代码之家  ›  专栏  ›  技术社区  ›  Kar

雪花分割部分函数不返回空值

  •  0
  • Kar  · 技术社区  · 5 年前

    '桌面£º'abc:voip●以Col1开始

    当我在雪花中运行下面的查询时,第二个\u值的值显示为空,而不是空值。如何获取此示例数据的空值

    select  'Desktop::abc:voip::GET STARTED' as Col1
            split_part($1:Col1 :: String, ':', 1) as First_Value,
            split_part($1:Col1 :: String, ':', 2)  as Second_Value,
            split_part($1:Col1 :: String, ':', 3) as Third_Value,
            split_part($1:Col1 :: String, ':', 4) as Fourth_Value;
    

    输出如下

    enter image description here

    0 回复  |  直到 5 年前
        1
  •  2
  •   waldente    5 年前

    可以使用NULLIF()将长度为零的字符串强制为null。例如:

    select  'Desktop::abc:voip::GET STARTED' as Col1,
    NULLiF(split_part(Col1 :: String, ':', 1),'') as First_Value,
    NULLiF(split_part(Col1 :: String, ':', 2),'') as Second_Value,
    NULLiF(split_part(Col1 :: String, ':', 3),'') as Third_Value,        
    NULLiF(split_part(Col1 :: String, ':', 4),'') as Fourth_Value
    
    推荐文章