本节内容:
mysql 中取子串函数 SUBSTR(SUBSTRING)
例1,pos 支持从结尾向前计数(负数)
例2,更新数据时使用substr函数。
UPDATE pic_recommend r,(
SELECT id,url,SUBSTR(url FROM 33) idhtml
FROM medical_pic_recommend
WHERE type=1
) t
SET r.article_id=SUBSTR(t.idhtml FROM 1 FOR LENGTH(t.idhtml)-5)
WHERE t.idhtml AND r.id=t.id;
UPDATE pic_recommend r,(
SELECT id,url,SUBSTR(url FROM 25) idhtml
FROM medical_pic_recommend
WHERE type=2
) t
SET r.article_id=SUBSTR(t.idhtml FROM 1 FOR LENGTH(t.idhtml)-5)
WHERE t.idhtml AND r.id=t.id;