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
How to replace specific values in a oracle database column?
提问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 est1
with rest1
)
应该是(替换est1
为rest1
)
column name
----------
Trest1
Test2
Test3
Trest12
回答by OMG Ponies
回答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_name
in the first argument of replace
did not work.
把t.column_name
中的第一个参数replace
没有工作。