Mysql 存储过程遍历Tag表(关键字表)的关键字,根据文章表的标题,为文章表的标签或关键字赋值。
DELIMITER $$ CREATE PROCEDURE UpdateKeywordsTags() BEGIN DECLARE P_id varchar(50) ; DECLARE P_keywords varchar(50) ; DECLARE P_count int ; DECLARE P_end_count int ; DECLARE C_WARRANTY CURSOR FOR SELECT ID,KEYWORDS FROM Table_tags ; SELECT COUNT(*) INTO P_end_count from Table_tags ; SET P_count = 0 ; OPEN C_WARRANTY; WHILE P_count < P_end_count DO FETCH C_WARRANTY INTO P_id,P_keywords; UPDATE Table_ARTICLE SET KEYWORDS = P_keywords , TAGS = P_keywords WHERE KEYWORDS IS NULL AND TITLE LIKE CONCAT('%',P_keywords,'%'); SET P_count = P_count+1; end while; CLOSE C_WARRANTY; END$$ DELIMITER ;
总结:通过以上方法就可以为文章表的标签和关键字赋值了,但效率很低,聊胜于无吧。总比一个一个手工去赋值好的多。