mysql 遊標的使用(儲存過程)

abin1703發表於2016-11-01
DELIMITER $$


USE `cms`$$


DROP PROCEDURE IF EXISTS `p2`$$


CREATE DEFINER=`root`@`%` PROCEDURE `p2`()
BEGIN
     DECLARE result VARCHAR(1280); 
    DECLARE v_PROGRAM_ID INT; 
     DECLARE NO INT;
     DECLARE cur_1 CURSOR FOR SELECT CONCAT(FINISH_PLATFORM_IDS,';105'),a.PROGRAM_ID FROM a a LEFT JOIN cms_program b ON a.PROGRAM_ID=b.PROGRAM_ID;
     DECLARE CONTINUE HANDLER FOR NOT FOUND SET NO=1; 
     SET NO=0; 
     OPEN cur_1; 
           WHILE NO=0 DO 
                 FETCH cur_1 INTO result,v_PROGRAM_ID;           
UPDATE cms_program SET FINISH_PLATFORM_IDS=result WHERE PROGRAM_ID=v_PROGRAM_ID;
           END WHILE;
     CLOSE cur_1;
END$$


DELIMITER ;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2127413/,如需轉載,請註明出處,否則將追究法律責任。

相關文章