这是问题所在: temprequest 是我从中获取行的表。我在获取时根据 temprequest 表查找可交付物表的 DeliverableId 列。因此我使用 select into 语句。但是我放置查找值的变量仅适用于获取的第一行。
“开始结束”块:
DECLARE no_more_rows BOOLEAN;
DECLARE nr_rows INT DEFAULT 0;
DECLARE loop_cntr INT DEFAULT 0;
declare delId int;
declare vtname varchar(200);
declare tversion varchar(200);
declare custId int;
declare prod varchar(200);
DECLARE c_temp CURSOR FOR select tname, version,BuID,BuprodName from temprequest;
SET no_more_rows = False;
OPEN c_temp;
select FOUND_ROWS() into nr_rows;
the_loop:LOOP
FETCH c_temp into vtname,tversion,custId, prod;
IF no_more_rows THEN
LEAVE the_loop;
END IF;
-- statements for each request record
Set delId= (SELECT deliverableId
FROM deliverable
WHERE deliverable.Product_prodName =vtname AND deliverable.version = tversion);
INSERT INTO request VALUES (delId, custId, prod);
SET loop_cntr = loop_cntr + 1;
END LOOP the_loop;
CLOSE c_temp;