How can I combine the LOCATE() and SUBSTR() functions in MySQL to create a new column? -
i have database table following layout, containing 100.000 entries:
id | url 1 | http://www.foo.com/zedfe.htm 2 | www.foo.com/tezqz.htm?q=eee 3 | foo.com/zeefg.htm 4 | http://www.foo.com/lkeio etc. i want have third column 5-character code of every url, see not every url formatted in same way. in php, this:
$id = substr($url, strpos($url,'foo.com/') + 8, 5); can done in mysql, using locate() , substr() functions?
another think more common point of view string operations legitimate part of sql , using them purpose describe quite appropriate.
here's basic list - you'll find familiar - use concat because there's no equivalent operator.
http://dev.mysql.com/doc/refman/5.5/en/string-functions.html
i found many examples when googled "mysql sql parse url". 1 interesting sample:
substring_index(substring_index(substring_index(trim(leading "https://" trim(leading "http://" trim(url))), "/", 1), ":", 1), ".", if(url "%.org.__%" or url "%.net.__%" or url "%.com.__%" or url "%.__.us%" or url "%.co.__%" or url "%.__.uk%", -3, -2) )
Comments
Post a Comment