0

I have strings values such as the following in a column:

<span style=text-align: justify;>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</span>

I want to perform a balanced string replacement as follows:

<p style=margin-top: 0;>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>

I have tried to do this with the REPLACE and CONCAT functions but didn't get the desired output.

For example:

mysql> SELECT REPLACE (
        contents,
        CONCAT( "<span style=text-align: justify;>", contents, "</span>" ),
CONCAT( "<p style=margin-top: 0;>", contents, "</p>" )) q 
FROM
    t_contents 
WHERE
    contents LIKE '%<span style=text-align: justify;>%';

+--------------------------------------------------------------------------------------------------------------------+
| q                                                                                                                  |
+--------------------------------------------------------------------------------------------------------------------+
| <span style=text-align: justify;>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</span> |
+--------------------------------------------------------------------------------------------------------------------+
1 row in set (0.14 sec)

How can I achieve this result in MySQL 8 version?

1 Answer 1

1

try something like this:

SELECT REPLACE( REPLACE(
'<span style=text-align: justify;>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</span>','<span style=text-align: justify;>','<p style=margin-top: 0;>'),
'</span>','</p>')
;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.