sql - Pulling a substring starting and ending with a special character from rows of a MySQL table -
i have table articles
column body
.
inside body
column, have lot of rows having <img>
tags, e.g
---------------------------------------- body ---------------------------------------- <img src="www.abc.com/1"> artcle 1 article 2 <img src="www.abc.com/2"> article 3 article 4
now want src
portions, www.abc.com/1
,www.abc.com/2
,etc.
i got such rows using
select body articles body `%img%`
how can extract link (src) portion?
you can use substr method locate , locate reverse find beginning double quote , ending double quote src="www.abc.com/1" so:
select body, substr( body, locate('"',body)+1, (char_length(body) - locate('"',reverse(body)) - locate('"',body)) ) 'src url' articles body '%img%'
Comments
Post a Comment