DROP PROCEDURE IF EXISTS proc_tmp;
CREATE PROCEDURE proc_tmp()
BEGIN
/*用于判断是否结束循环*/
DECLARE done INT DEFAULT 0;
/*用于存储结果集记录*/
DECLARE_om_id INT ( 11 );
/*定义游标*/
DECLAREidCur CURSOR FOR
SELECT DISTINCT om_id FROM tt_order_attr_mapping WHERE om_id NOT IN ( SELECT DISTINCT om_id FROM tt_order_attr_mapping WHERE s_attr = 'IS_UNDER_CALL' );
/*定义 设置循环结束标识done值怎么改变 的逻辑*/
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
/*打开游标*/
OPEN idCur;
/* 循环开始 */
REPEAT
FETCH idCur INTO _om_id;
IF NOT done THEN
/*数值为非0,MySQL认为是true*/
INSERT INTO tt_order_attr_mapping ( `om_id`, `s_attr`, `d_attr`, `defaultvalue`, `update_userid`, `update_time` ) VALUES ( _om_id, 'IS_UNDER_CALL', NULL, '0', NULL, NULL );
END IF;
UNTIL done END REPEAT;
/*关闭游标*/
CLOSE idCur;
END;
/* 循环结束 */
CALL proc_tmp();
/*删除临时存储过程*/
DROP PROCEDURE proc_tmp;