【问题标题】:Replace just start of string in sql替换sql中字符串的开头
【发布时间】:2015-01-28 14:19:07
【问题描述】:

我的表中有 3 列:

+-+-+-+-+-+-+-+-+-+-+-++
+ ID + Name +   Cell   +
++++++++++++++++++++++++
+  1  +  FB + /moon/ta +
+  2  +  GO + /ta/ta   +
+  3  +  MO + /ta/mon  +
+  4  +  SS + /ta      +
+  4  +  SS + /ta/o/ta +
+-+-+-+-+-+-+-+-+-+-+-++

我想用字符串开头的单元格中的“/rr”替换所有“/ta”,例如:

+-+-+-+-+-+-+-+-+-+-+-++
+ ID + Name +   Cell   +
++++++++++++++++++++++++
+  1  +  FB + /moon/ta +
+  2  +  GO + /rr/ta   +
+  3  +  MO + /rr/mon  +
+  4  +  SS + /rr      +
+  4  +  SS + /rr/o/ta +
+-+-+-+-+-+-+-+-+-+-+-++

如何在 SQL 中执行此操作?

【问题讨论】:

    标签: mysql sql replace


    【解决方案1】:

    我认为这是你想要的:

    update table t
        set cell = concat('/rr', substr(cell, 4))
        where cell like '/ta%';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 2011-02-07
      • 2023-01-07
      • 2016-12-18
      • 1970-01-01
      • 2014-03-07
      • 2021-07-09
      相关资源
      最近更新 更多