mysql存储过程循环修改每一条数据

来源:互联网 发布:西部数据如何解析域名 编辑:程序博客网 时间:2024/05/02 19:50
DELIMITER $$USE `health`$$DROP PROCEDURE IF EXISTS `repairDiseaseData`$$CREATE DEFINER=`root`@`%` PROCEDURE `repairDiseaseData`()BEGIN      DECLARE Done INT DEFAULT 0;      DECLARE isSeeDoctor INT;  DECLARE dId INT;      DECLARE seeDoctorMsg LONGTEXT;      DECLARE rs CURSOR FOR   SELECTid,is_see_doctor,see_doctor_msg  FROMt_disease  WHERE( (is_see_doctor = 0OR is_see_doctor IS NULL) AND see_doctor_msg IS NOT NULL AND see_doctor_msg != '')  OR (is_see_doctor = 1AND (see_doctor_msg IS NULL OR see_doctor_msg = ''));      DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;      OPEN rs;    FETCH NEXT FROM rs INTO dId, isSeeDoctor, seeDoctorMsg;           REPEAT        IF NOT Done THEN            IF seeDoctorMsg is null or seeDoctorMsg = ''THEN                UPDATE t_disease SET is_see_doctor = 0 WHERE id = dId;            ELSE                               UPDATE t_disease SET is_see_doctor = 1 WHERE id = dId;            END IF;        END IF;        FETCH NEXT FROM rs INTO dId, isSeeDoctor, seeDoctorMsg;         UNTIL Done END REPEAT;  CLOSE rs;END$$DELIMITER ;CALL repairDiseaseData();

0 0
原创粉丝点击