Mysql 查找行数,添加1,然后替换字符串
我有类似的行Mysql 查找行数,添加1,然后替换字符串,mysql,Mysql,我有类似的行 a:1:{s:5:“值;s:69:”https://www.mypage.com/files/products/product.jpg“;} 我想提取数字69,添加1,并用替换整个字符串 a:1:{s:5:“值;s:70:”https://www.mypage.com/files/products/product.jpg“;} 如何处理这个问题?在mysql中可以这样做吗 我使用mysql 5.5 谢谢。试试这样的 SELECT REPLACE(col, Substring_ind
a:1:{s:5:“值;s:69:”https://www.mypage.com/files/products/product.jpg“;}
我想提取数字69,添加1,并用替换整个字符串
a:1:{s:5:“值;s:70:”https://www.mypage.com/files/products/product.jpg“;}
如何处理这个问题?在mysql中可以这样做吗
我使用mysql 5.5
谢谢。试试这样的
SELECT REPLACE(col, Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1),
Cast(Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1) AS UNSIGNED) + 1) AS col
FROM TableName
要更新数据,请执行以下操作
UPDATE TableName
SET col = REPLACE(col, Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1),
Cast(Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1) AS UNSIGNED) + 1);
逐步查询
步骤01
SELECT *
FROM TableName
+-----------------------------------------------------------------------------+
| col |
+-----------------------------------------------------------------------------+
| a:1:{s:5:"value";s:69:"https://www.mypage.com/files/products/product.jpg";} |
+-----------------------------------------------------------------------------+
步骤02-获取值
步骤03-添加+1
步骤04-用新值替换该值
< MySQL没有本地PHP解析器,你应该考虑使用JSON来代替或规范数据。结果仍然是一个破损的序列化。考虑升级到8(或MariaDB),以便获得<代码> ReGeExpRePoT()/Cyto>。我不得不删除带有“”的部分-这在mysql 5.5中显然是错误的语法。但是新数据没有写入数据库,我只能在屏幕上看到正确的结果。这是我的测试代码选择替换(content,Substring_index(Substring_index)(content,;s:',-1),':',1),Cast(内容“;s:”,-1),“:”,1)作为未签名)+1)作为来自nodewords的内容,其中id='1',name='og:image'和类似于“%http%”的内容,I managet使其工作方式如下“UPDATE
nodewords
SET content=REPLACE(content,Substring_index)(Substring_index(content,;s:',-1),':',1),Cast(Substring_index)(Substring_index)(Substring)(内容“;s:”,-1),“:”,1)未签名)+1)其中id='1'和名称='og:image'以及类似“%http%”的内容。非常感谢您的帮助。不客气。感谢您选择此作为接受的答案。
SELECT Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1)
FROM TableName
+-----------------------------------------------------------------------+
| Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1) |
+-----------------------------------------------------------------------+
| 69 |
+-----------------------------------------------------------------------+
SELECT Cast(Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1) AS UNSIGNED) + 1
FROM TableName
+---------------------------------------------------------------------------------------------+
| Cast(Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1) AS UNSIGNED) + 1 |
+---------------------------------------------------------------------------------------------+
| 70 |
+---------------------------------------------------------------------------------------------+
SELECT REPLACE(col, Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1),
Cast(Substring_index(Substring_index(col, '"value";s:', -1), ':"http', 1) AS UNSIGNED) + 1) AS col
FROM TableName
+-----------------------------------------------------------------------------+
| col |
+-----------------------------------------------------------------------------+
| a:1:{s:5:"value";s:70:"https://www.mypage.com/files/products/product.jpg";} |
+-----------------------------------------------------------------------------+