he...">

SQL string replaces pattern

I have a table X with a column Y that contains the text as follows:

Click <a href=""http://www.stackoverflow.com"">here</a> to redeem 

I need it to turn into:

 Click <a href="http://www.stackoverflow.com">here</a> to redeem 

i.e. remove an extra pair of quotation marks

Text outside url can be anything.

Is it something like this?

 Update X SET Y = REPLACE(Y, '""%""', '"%"' ); 
+4
source share
4 answers

REPLACE replaces all occurrences of the second parameter with the third parameter:

 update X set Y = replace(Y, '""', '"') 
+6
source
 select replace('Click <a href=""http://www.stackoverflow.com"">here</a> to redeem','""','"') 

I use select to check what the update will do before doing the update.

0
source

You need to replace "with", so do the following:

 Update X SET Y = REPLACE(Y, '""', '"') 
0
source

You need to replace "with", so do the following:

 Update X SET Y = REPLACE(Y, '""', '"') WHERE y LIKE '""%""'; 

Use with a dose of caution because it will also replace text, for example:

 Click <a href="http://www.stackoverflow.com">""here""</a> to redeem 

in

 Click <a href="http://www.stackoverflow.com">"here"</a> to redeem 
0
source

Source: https://habr.com/ru/post/1389102/


All Articles