Regexp_replace替换特定值

时间:2019-12-12 05:32:29

标签: sql regex oracle

我在不同位置的列中有数据,我想使用regexp_replace()替换。

列值:

  

业务解决方案,管理服务,信用管理服务,   商业解决方案,信用

在列中,我想用业务解决方案替换业务解决方案。

请指导

2 个答案:

答案 0 :(得分:1)

有帮助吗?

    SELECT
           REGEXP_REPLACE('Business solution, Business solutions, management services, credit Management services, business solution, credit'
          , 
'(^|[^[:alpha:]])business solution([^[:alpha:]]|$)','\1business solutions\2', 1, 0, 'i')

    from
          DUAL;

答案 1 :(得分:0)

您可以通过两种方式使用regexp_replace

区分大小写的方式:

SQL>
SQL> SELECT
  2      REGEXP_REPLACE('Business solution, management services, credit Management services, business solution, credit'
  3      , 'business solution'
  4      , 'business solutions')
  5  FROM
  6      DUAL;

REGEXP_REPLACE('BUSINESSSOLUTION,MANAGEMENTSERVICES,CREDITMANAGEMENTSERVICES,BUSINESSSOLUTION,
----------------------------------------------------------------------------------------------
Business solution, management services, credit Management services, business solutions, credit

SQL>
通过将match_parameter用作'i'

不区分大小写的方式

SQL>
SQL> SELECT
  2      REGEXP_REPLACE('Business solution, management services, credit Management services, business solution, credit'
  3      , 'business solution'
  4      , 'business solutions', 1, 0, 'i')
  5  FROM
  6      DUAL;

REGEXP_REPLACE('BUSINESSSOLUTION,MANAGEMENTSERVICES,CREDITMANAGEMENTSERVICES,BUSINESSSOLUTION,C
-----------------------------------------------------------------------------------------------
business solutions, management services, credit Management services, business solutions, credit

SQL>

干杯!