sql 替换一列中的两个字符串
sql to replace two strings in one column
我想替换单个字符串中的两个字符。
替换
Name
I am not aware of any or potential that hasn’t yet been reported
和
Name
I am not aware of any/potential that hasn't yet been reported
我用过这个查询:
replace(Replace(Name, ' or ', '/'), '’', ''')
但是我得到一个错误
ORA-01756: quoted string not properly terminated
我真的不明白你想用你的双重替换做什么。你可以只使用一个:
SELECT REPLACE(name,' or ','/') newstring FROM yourstrings;
如果你真的需要双重替换,你也可以这样做:
SELECT REPLACE(REPLACE(name,' or ','/'),'’','''') newstring FROM yourstrings;
更有趣的是如何插入包含撇号、引号等的字符串。您可以使用 q 运算符来完成,例如:
INSERT INTO yourstrings VALUES
(q'[I am not aware of any or potential that hasn’t yet been reported ]');
请看这个工作示例:db<>fiddle
select replace(replace
('I am not aware of any or potential that hasn’t yet been reported',' or ','/'),
'’','''')
from dual;
参考解决方案here
我想替换单个字符串中的两个字符。
替换
Name
I am not aware of any or potential that hasn’t yet been reported
和
Name
I am not aware of any/potential that hasn't yet been reported
我用过这个查询:
replace(Replace(Name, ' or ', '/'), '’', ''')
但是我得到一个错误
ORA-01756: quoted string not properly terminated
我真的不明白你想用你的双重替换做什么。你可以只使用一个:
SELECT REPLACE(name,' or ','/') newstring FROM yourstrings;
如果你真的需要双重替换,你也可以这样做:
SELECT REPLACE(REPLACE(name,' or ','/'),'’','''') newstring FROM yourstrings;
更有趣的是如何插入包含撇号、引号等的字符串。您可以使用 q 运算符来完成,例如:
INSERT INTO yourstrings VALUES
(q'[I am not aware of any or potential that hasn’t yet been reported ]');
请看这个工作示例:db<>fiddle
select replace(replace
('I am not aware of any or potential that hasn’t yet been reported',' or ','/'),
'’','''')
from dual;
参考解决方案here