【问题标题】:Using regexp_replace in update在更新中使用 regexp_replace
【发布时间】:2013-07-12 00:29:15
【问题描述】:

我有一个 db 列 report_name,其值与此类似

000007091_PaymentRegisterReport _D x3A 975844_2012-12-26.XLS

我需要删除所有带有 XLS 扩展名的 PaymentRegisterReport 中 _D 之前的空格。 有人可以帮助我使用正则表达式在更新语句中使用内部 regexp_replace 函数吗?

【问题讨论】:

    标签: sql regex oracle


    【解决方案1】:

    您真的需要正则表达式来更新数据吗?请检查查询。

    update TableName
    set report_name=REPLACE(report_name, ' _D' , '_D')
    WHERE report_name LIKE '%PaymentRegisterReport %' AND 
      report_name LIKE '%.XLS';
    

    【讨论】:

      【解决方案2】:

      你需要使用的表达式是

      REGEXP_REPLACE(f1, '(.*)(_PaymentRegisterReport) _D (.*)(\.XLS)$', '\1\2_D\3\4')
      

      我假设您可以通过“PaymentRegisterReport”识别报告类型,并且文件扩展名将是大写的

      【讨论】:

        【解决方案3】:

        您可以将“_D”bi“_D”替换为上述techdo的选择。

        但是我按照你的要求写了一个 regex_replace :

        select regexp_replace('000007091_PaymentRegisterReport _D x3A 975844_2012-12-26.XLS','^(.*) _D(.*).XLS$','\1_D\2.XLS') from dual;
        

        【讨论】:

          猜你喜欢
          • 2018-10-22
          • 2021-02-08
          • 2018-02-11
          • 2017-02-26
          • 2019-07-02
          • 2016-10-25
          • 2015-06-15
          • 1970-01-01
          • 2017-01-11
          相关资源
          最近更新 更多