[英]multiple substring in a string mysql
the fulltext field contains html tags and some resources and I want to get all 'src' attributes from that. 全文字段包含html标记和一些资源,我想从中获取所有的'src'属性。 some records maybe have several 'src'.
有些记录可能有几个“ src”。
now, I dont know how I can write a query to obtain the desired result. 现在,我不知道如何编写查询以获得所需的结果。 and this is my code
这是我的代码
DROP FUNCTION IF EXISTS SPLIT_STR;
CREATE FUNCTION SPLIT_STR(
x text,
delim VARCHAR(10),
co INT
)
RETURNS VARCHAR(255) DETERMINISTIC
BEGIN
WHILE co >= 0 DO
SET x = RIGHT(x, ( (CHAR_LENGTH(x)) - (InStr(x,'src')) + 1 ));
RETURN SUBSTR(x, 1, 40);
END WHILE;
END
#---------------------------------------------------
SELECT id, SPLIT_STR(test.fulltext, 'src',ROUND (
(
LENGTH(test.fulltext)
- LENGTH( REPLACE ( test.fulltext, "src", "") )
) / LENGTH("src")
))
FROM test
WHERE test.fulltext LIKE '%src%'
Function ExtractValue works with xml in mysql. 函数ExtractValue与mysql中的xml一起使用。 So, you can use this:
因此,您可以使用以下代码:
SELECT ExtractValue(test.fulltext, '//img/@src')
FROM test
WHERE test.fulltext LIKE '%src%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.