zoukankan      html  css  js  c++  java
  • GreenPlum学习笔记:split_part与string_to_array字符截取

      偶遇一个需求:想按某个指定符号分割之后,提取字符。

      例如:tag = '休闲,娱乐,运动,玩耍',想提取"休闲"这个词。

    方法一:string_to_array

    select string_to_array('休闲,娱乐,运动,玩耍','');
    ------------------------------
    -- {休闲,娱乐,运动,玩耍}
    -- (1 row)
    select tag[1] from (
        select string_to_array('休闲,娱乐,运动,玩耍','')
     as tag ) a
    ---------------------
    -- 休闲
    -- (1 row)

    如此实现,但是string_to_array需要子查询,当与其他自动group by一起查询的时候就显得及其不方便,因此可使用方法二。

    方法二:split_part

    select split_part('休闲,娱乐,运动,玩耍','',1);
    -----------------
    -- 休闲
    -- (1 row)
    
    select split_part('abc~@~def~@~ghi','~@~',2)
    -----------------
    -- def
    -- (1 row)

    END 2018-08-01 17:03:18

  • 相关阅读:
    poj 1200 crasy search
    cdoj 1092 韩爷的梦
    fzu 2257 saya的小熊饼干
    zoj 3950 how many nines
    zoj 3963 heap partion
    fzu 2256 迷宫
    fzu 2253 salty fish
    hdu 2473 Junk-Mail Filter
    codeforces 129B students and shoes
    hdu 3367 Pseudoforest
  • 原文地址:https://www.cnblogs.com/hider/p/9402337.html
Copyright © 2011-2022 走看看