mysql函数集

DELIMITER $
#用来批量复制某个栏目下的文章到另一个栏目下
DELIMITER $$

USE `web`$$

DROP FUNCTION IF EXISTS `addCategory`$$

CREATE DEFINER=`root`@`localhost` FUNCTION `addCategory`(cid INT, newcid INT) RETURNS VARCHAR(255) CHARSET utf8
BEGIN
DECLARE contentid2 INT DEFAULT 0;
DECLARE contentid3 INT DEFAULT 0;
DECLARE curid CURSOR FOR SELECT contentid FROM web_content WHERE catid=cid;
OPEN curid;
REPEAT
FETCH curid INTO contentid2;
INSERT INTO web_content(catid,typeid,areaid,title, style, thumb, keywords, posids, url, listorder,STATUS, userid, username, inputtime, updatetime) SELECT newcid,typeid,areaid,title, style, thumb, keywords, posids, url, listorder,`STATUS`, userid, username, inputtime, updatetime FROM web_content WHERE contentid=contentid2;
SET contentid3 = LAST_INSERT_ID();
REPLACE INTO web_c_news(contentid, template, titleintact, content, groupids_view, readpoint, author, copyfrom,paginationtype,maxcharperpage) SELECT contentid3,template, titleintact, content, groupids_view, readpoint, author, copyfrom,paginationtype,maxcharperpage FROM web_c_news WHERE contentid=contentid2;
UNTIL !contentid2 END REPEAT;
CLOSE curid;
RETURN “”;
END$$

DELIMITER ;