【问题标题】:Is there any Regexp_count alternative in Impala?Impala 中是否有任何 Regexp_count 替代方案?
【发布时间】:2022-01-12 18:22:57
【问题描述】:

我正在 Impala 中寻找 Oracle 的 Regexp_count 替代方案。是否有任何替代方案或有什么方法可以在 Impala 中实现 regexp_count?

【问题讨论】:

    标签: sql oracle impala


    【解决方案1】:

    用一些不在你的模式中的字符替换模式,比如波浪号'~',然后删除所有不是波浪号的字符,然后计算字符串的长度。如果初始字符串可以包含波浪号,请将它们全部删除。

    例如计算模式test在字符串中出现的次数(也包含波浪线)'test ~something ~test, one more test~':

    length(--get length (the number of tildes)
                  regexp_replace(
                                 regexp_replace(
                                                regexp_replace('test ~something ~test, one more test~','~',''), --remove all tildes
                                                'test','~'), --replace pattern with tilde
                                  '[^~]+','') --remove everything that is not tilde
                  ) --calculate the number of tildes
    

    这将返回 3

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 1970-01-01
      • 2011-06-07
      • 2012-05-03
      • 2020-07-13
      • 1970-01-01
      • 2020-04-14
      • 2019-06-16
      • 1970-01-01
      相关资源
      最近更新 更多