SQL 如何替换 oracle 数据库列中的特定值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3443156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 07:08:59  来源:igfitidea点击:

How to replace specific values in a oracle database column?

sqloraclereplace

提问by schar

I am looking to replace values in a particular column. For example the following column values

我正在寻找替换特定列中的值。例如以下列值

column name
----------
Test1
Test2
Test3
Test12

should be (replacing est1with rest1)

应该是(替换est1rest1

column name
----------
Trest1
Test2
Test3
Trest12

回答by OMG Ponies

Use REPLACE:

使用替换

SELECT REPLACE(t.column, 'est1', 'rest1')
  FROM MY_TABLE t

If you want to update the values in the table, use:

如果要更新表中的值,请使用:

UPDATE MY_TABLE t
   SET column = REPLACE(t.column, 'est1', 'rest1')

回答by Babatunde Adeyemi

If you need to update the value in a particular table:

如果您需要更新特定表中的值:

UPDATE TABLE-NAME SET COLUMN-NAME = REPLACE(TABLE-NAME.COLUMN-NAME, 'STRING-TO-REPLACE', 'REPLACEMENT-STRING');

where

在哪里

  TABLE-NAME         - The name of the table being updated
  COLUMN-NAME        - The name of the column being updated
  STRING-TO-REPLACE  - The value to replace
  REPLACEMENT-STRING - The replacement

回答by Praveen Mishra

In Oracle, there is the concept of schema name, so try using this

在 Oracle 中,有模式名的概念,所以尝试使用这个

update schemname.tablename t
set t.columnname = replace(t.columnname, t.oldvalue, t.newvalue);

回答by Thomas Robert Horn

I'm using Version 4.0.2.15 with Build 15.21

我使用版本 4.0.2.15 和 Build 15.21

For me I needed this:

对我来说,我需要这个:

UPDATE table_name SET column_name = REPLACE(column_name,"search str","replace str");

Putting t.column_namein the first argument of replacedid not work.

t.column_name中的第一个参数replace没有工作。