简体   繁体   English

在 MySQL 8 版本中使用替换和连接

[英]Using replace and concat in MySQL 8 version

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.我尝试使用 REPLACE 和 CONCAT 函数来执行此操作,但没有得到所需的 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?如何在 MySQL 8 版本中实现此结果?

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>')
;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM