代码之家  ›  专栏  ›  技术社区  ›  TRomesh

如何更新具有特定字符串模式/序列的列

  •  -1
  • TRomesh  · 技术社区  · 7 年前

    'A=xxx^B=xxx^C=xxx^D=xxx^' 我需要将所有具有此模式的列更新为 'C=xxx^D=xxx^'

    2 回复  |  直到 7 年前
        1
  •  1
  •   Littlefoot    7 年前

    REGEXP_LIKE SUBSTR 返回所需的结果。

    SQL> with test (col) as
      2    (select 'A=123^B=123^C=123^D=123^'       from dual union
      3     select 'A=123^B=456^C=789^D=987^'       from dual union
      4     select 'A=333^C=333^D=333^'             from dual union
      5     select 'C=987^D=987^'                   from dual union
      6     select 'B=876^'                         from dual union
      7     select 'A=123^B=123^C=123^D=123^E=123^' from dual
      8    )
      9  select col,
     10    substr(col, instr(col, 'C')) result
     11  from test
     12  where regexp_like(col, '^A=\d+{3}\^B=\d+{3}\^C=\d+{3}\^D=\d+{3}\^$');
    
    COL                            RESULT
    ------------------------------ ------------------------------
    A=123^B=123^C=123^D=123^       C=123^D=123^
    A=123^B=456^C=789^D=987^       C=789^D=987^
    
    SQL>
    
        2
  •  1
  •   TRomesh    7 年前

    'A=' 我用过 找到那个特定的模式。然后我用 从应该从第2个开始的字符串中提取值 '^'

    Update MYTABLE t set t.key = SUBSTR(t.key,INSTR(t.key,'^',1,2)+1) WHERE REGEXP_LIKE(t.key_ref,'^A=') and t.dno = 'xxxxx';