【问题标题】:upate statement using replace in PostgreSQL在 PostgreSQL 中使用替换更新语句
【发布时间】:2020-05-26 17:16:50
【问题描述】:

我的表格有以下记录

Sno  A
-    --
1   spoo74399p 
2   spoo75399p 

我想通过将oo(字母'o')替换为零来更新上述记录

Required OUTPUT
----------------
Sno     A

1   sp0074399p 
2   sp0075399p 

【问题讨论】:

标签: sql postgresql sql-update postgresql-9.2


【解决方案1】:

我想通过将oo(字母'o')替换为零来更新上述记录

这是你要找的吗?

update mytable set a = replace(a, 'oo', '00')

【讨论】:

    【解决方案2】:

    我可能会在这里使用REGEXP_REPLACE 尽可能具体:

    UPDATE yourTable
    SET A = REGEXP_REPLACE(A, '^spoo', 'sp00');
    

    这只会针对出现在开头附近的oo,在sp之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      相关资源
      最近更新 更多