'sql to replace two strings in one column [duplicate]
I want to replace two characters in a single string.
Replace
Name
I am not aware of any or potential that hasn’t yet been reported
with
Name
I am not aware of any/potential that hasn't yet been reported
I've used this query:
replace(Replace(Name, ' or ', '/'), '’', ''')
But I get an error
ORA-01756: quoted string not properly terminated
Solution 1:[1]
I don't really understand what you ary trying to do with your double replace. You can just use one:
SELECT REPLACE(name,' or ','/') newstring FROM yourstrings;
If you really need a double replace, you can do this, too:
SELECT REPLACE(REPLACE(name,' or ','/'),'’','''') newstring FROM yourstrings;
More interesting is how to insert such strings which contain apostrophes, quotes etc. You can do it using the q operator, as example:
INSERT INTO yourstrings VALUES
(q'[I am not aware of any or potential that hasn’t yet been reported ]');
Please see this working example: db<>fiddle
Solution 2:[2]
select replace(replace
('I am not aware of any or potential that hasn’t yet been reported',' or ','/'),
'’','''')
from dual;
Refer solution here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Pankaj |
