简体   繁体   中英

MySQL SubString to extract exact part

I have a challenge as for my lack of knowledge in SQL.

I have a column in my database where I save this:

 <div class="product-cover" style="border:none;"> <div class="images-container"> <div class="images-container"><img src="https://myurl.com/img/cms/_DSC6641.jpg" title="" alt="" /></div> </div> 

I am trying to extract the string " https://myurl.com/img/cms/_DSC6641.jpg " which is different for every row.

Is it possible to create a query to extract that exact part in between src="..." ?

I am using MySQL/MariaDB

我会用substring_index()

select substring_index(substring_index(col, '<div class="images-container"><img src=', -1), ' ', 1)

I have found a way using the reply from D-Shih

 SELECT SUBSTRING( pl.description, LOCATE('src="',pl.description) + CHAR_LENGTH('src="'), ( LOCATE('" title', pl.description)) - ( LOCATE('src="', pl.description) + CHAR_LENGTH('src="') ) ) as url FROM ps_product p INNER JOIN ps_product_lang pl ON (pl.id_product=p.id_product) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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