CREATE DEFINER = 'root'@'localhost' PROCEDURE zswms.test2() begin declare package_id_ varchar(20); declare done int ; declare cur cursor for SELECT DISTINCT package_id FROM shipment_serial_error WHERE package_id IN (SELECT boxnum FROM amwcs.nw_scnlog ); declare continue handler for not found set done=1; open cur; posLoop:Loop fetch cur into package_id_; if done=1 then leave posLoop; END IF; CALL AmwayWcsUtil_ReadNwSerial(package_id_); commit; end LOOP posLoop; close cur; end