รายละเอียดของการตอบ ::
DELIMITER ;;
DROP PROCEDURE IF EXISTS TBLSYNC;;
CREATE PROCEDURE TBLSYNC()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE counter INT DEFAULT 0;
DECLARE h_id INT DEFAULT 0;
DECLARE addrpart_tmp VARCHAR(50);
DECLARE pt_cursor CURSOR FOR SELECT addrpart FROM `new` WHERE addrpart not in (SELECT address FROM `house`);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SELECT max(house_id) FROM `house` INTO h_id;
OPEN pt_cursor;
read_loop: LOOP
FETCH NEXT FROM pt_cursor INTO addrpart_tmp;
IF done THEN
LEAVE read_loop;
END IF;
SET h_id = h_id+1;
INSERT ignore INTO house (house_id, address, road )
SELECT h_id, addrpart, road
FROM new as n where not exists (select * from house where n.addrpart = address);
END LOOP;
CLOSE pt_cursor;
END;
;;
DELIMITER ;
CALL TBLSYNC();
**** รันผ่านแต่ข้มฤูลไม่เข้าไปสร้างที่อยู่ใหม่ให้ตารางบ้านครับ