测试时用存储过程来修改测试数据

在测试时,可能会需要制造些假数据来测试,此时可以用存储过程来实现差异化的数据

代码如下:

DROP PROCEDURE IF EXISTS test;
DELIMITER //
CREATE PROCEDURE test()
BEGIN
	DECLARE dat DATETIME DEFAULT DATE_SUB(NOW(), INTERVAL 1 DAY);
	DECLARE m_id INT;
	DECLARE done INT DEFAULT 0;
	DECLARE cur CURSOR FOR SELECT merchant_id FROM merchant WHERE is_recommend = 1 AND biz_type = 1 AND STATUS = 1;
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
	
	OPEN cur;
	l1:LOOP
		FETCH cur INTO m_id;
		
		IF done = 1 THEN 
			LEAVE l1;
		END IF;
		
		SET dat = DATE_ADD(dat, INTERVAL 1 SECOND);
		UPDATE merchant SET recommend_time = dat WHERE merchant_id = m_id;
	END LOOP l1;
	
	CLOSE cur;
END//

DELIMITER ;

CALL test;


你可能感兴趣的:(数据库)