代码之家  ›  专栏  ›  技术社区  ›  Dikshit Karki

如何在oracle中从空间中提取单词?

  •  0
  • Dikshit Karki  · 技术社区  · 5 年前

    我在列文件名中有一个句子,例如:

    filename
    Exact filename from California Dec 2015
    Exact filename from Austin Jan 2015
    

    我只想从中提取日期部分,就像我的预期输出是:

    filename
    Dec 2015
    Jan 2015
    

    select regexp_substr(regexp_replace(filename
                                       ,'[[:space:]]-[[:space:]]'
                                       ,chr(11))
                        ,'([^'||chr(11)||']*)('||chr(11)||'|$)'
                        ,1 -- Start here
                        ,4 -- return 1st, 2nd, 3rd, etc. match
                        ,null
                        ,1 -- return 1st sub exp
                        )
    

    我尝试的另一种方法是:

    regexp_like(filename,'(^[:space:]|[:space:]$)');
    

    然而,这两种方法对我都不起作用,我搜索了更多,但没有得到。

    1 回复  |  直到 5 年前
        1
  •  1
  •   Vasan    5 年前

    select regexp_substr(filename, '[^[:space:]]+[[:space:]][^[:space:]]+$') from table;
    

    此表达式匹配:(any except space)(space)(any except space)(end)

    注意,这只允许最后两个单词之间有一个空格字符。