を使用しています、あなたは一時テーブルとWhile..Do文を使用して反復することができます。
はのは、以下のルーチンを作成し、検証プロセスを調整する2つのテーブル
CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
そして
CREATE TABLE `tmp_user` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
を持っているとしましょう:INSERTを見てみましょう
DELIMITER $$
USE `routines_sample`$$
CREATE PROCEDURE `nocursor`()
BEGIN
Declare validId int;
Declare validName varchar(45);
-- drop the temporary table if exists
Drop table if exists `routines_sample`.tmp_validation;
-- create the temporary table, here you could use Engine=Memory
Create table `routines_sample`.tmp_validation (`id` int not null, `name` varchar(45) not null, `valid` bit(1) not null) Engine=MyISAM;
-- insert into the temporary table with a valid flag = 0 (false)
Insert into `routines_sample`.tmp_validation (`id`, `name`, `valid`)
Select tu.id, tu.name, 0
From `routines_sample`.tmp_user tu;
-- while exists data to validate on temporary table do something
While exists(Select `id` From `tmp_validation` Where `valid` = 0) Do
Select `id`, `name` Into @validId, @validName From tmp_validation Where `valid` = 0 Limit 1;
-- do your validation
Select @validId, @validName;
-- don't forget to update your validation table, otherwise you get an endless loop
Update `tmp_validation`
Set `valid` = 1
Where `id` = @validId;
END WHILE;
-- insert only valid rows to your destination table
Insert into `routines_sample`.`user` (`name`)
Select `name` From `tmp_validation`
Where `valid` = 1;
-- drop the temporary table
DROP TABLE tmp_validation;
END$$
DELIMITER ;
... SELECT文 - http://dev.mysql.com/doc/refman/5.1/en/insert-select.html – Devart
検証ルールとは何ですか/ cオデ?検証が大雑把かどうか、または検証が行に依存しないかどうかを知ることは不可欠です。 – Nonym