2017-03-09 17 views
-4

这是我的SP当我运行它,我得到的错误:这是我的SP ..am得到结果由一个以上的row.please的帮我

result consisted of multiple rows

CREATE DEFINER=`root`@`localhost` PROCEDURE `fourandfive`(IN choice varchar(10), IN upcstring varchar(100), IN Skustring varchar(100)) 
BEGIN 
set @numberofUpcs = length(upcstring); 
set @numberofSkus = length(Skustring); 
DROP TEMPORARY TABLE IF EXISTS upcs; 
create temporary table upcs (upcValue varchar(20)); 

while (@numberofUpcs>0) do 

set @oneupc = substring_index(upcstring,',',1); 

insert into upcs values(@oneupc); 

set @next = substr(upcstring,1,length(@oneupc)+1); 

set upcstring = replace(upcstring,@next,''); 

#select @next, @oneupc, upcstring; 



set @numberofUpcs = length(upcstring); 


end while; 



DROP TEMPORARY TABLE IF EXISTS skus; 
create temporary table skus (skuValue varchar(20)); 

while (@numberofSkus>0) do 

set @onesku = substring_index(Skustring,',',1); 

insert into skus values(@onesku); 

set @next = substr(Skustring,1,length(@onesku)+1); 

set Skustring = replace(Skustring,@next,''); 

#select @next, @oneupc, upcstring; 



set @numberofSkus = length(Skustring); 


end while; 




select count(*) from upcs into @upclen; 


#final loop 

while(@upclen>=1) do 

select upcValue into @Upc from upcs limit 1; 
select skuValue into @Sku from skus limit 1; 


IF(choice='four') THEN 

select shipping into @shipping from store_data where upc = @Upc and sku = @Sku limit 1; 
select ([email protected]) into @reprice from prices where upc = @Upc and sku = @Sku limit 1; 
update revised_price set price = @reprice where upc = @Upc; 
delete from skus where skuValue = @Sku; 
set @Sku = 0; 

#select @shipping,@reprice; 


ELSE IF(choice = 'five') then 
select min(price) into @minimumprice from prices where upc= @Upc group by upc; 
update revised_price set price = @minimumprice where upc = @Upc; 
end if; 
end if; 
set @upclen = @upclen-1; 
delete from upcs where upcValue = @Upc; 
set @Upc = 0; 
end while; 
drop table upcs; 
drop table skus; 

END 
+2

请不要指望我们找到错误发生的位置,但指向我们的位置! – Shadow

回答

0
DROP PROCEDURE fourandfive; 
DELIMITER $$ 

CREATE PROCEDURE fourandfive(IN choice varchar(10),IN upcstring VARCHAR(255),IN Skustring varchar(100)) 
BEGIN 
set @numberofUpcs = length(upcstring); 
set @numberofSkus = length(Skustring); 
DROP TEMPORARY TABLE IF EXISTS upcs; 
create temporary table upcs (upcValue varchar(20)); 

while (@numberofUpcs>0) do 

set @oneupc = substring_index(upcstring,',',1); 

insert into upcs values(@oneupc); 

set @next = substr(upcstring,1,length(@oneupc)+1); 

set upcstring = replace(upcstring,@next,''); 

#select @next, @oneupc, upcstring; 



set @numberofUpcs = length(upcstring); 


end while; 



DROP TEMPORARY TABLE IF EXISTS skus; 
create temporary table skus (skuValue varchar(20)); 

while (@numberofSkus>0) do 

set @onesku = substring_index(Skustring,',',1); 

insert into skus values(@onesku); 

set @next = substr(Skustring,1,length(@onesku)+1); 

set Skustring = replace(Skustring,@next,''); 

#select @next, @oneupc, upcstring; 



set @numberofSkus = length(Skustring); 


end while; 




select count(*) from upcs into @upclen; 


#final loop 

while(@upclen>=1) do 

select upcValue into @Upc from upcs limit 1; 
select skuValue into @Sku from skus limit 1; 


IF(choice='four') THEN 

select shipping into @shipping from store_data where upc = @Upc and sku = @Sku limit 1; 
select ([email protected]) into @reprice from prices where upc = @Upc and sku = @Sku limit 1; 
update revised_price set price = @reprice where upc = @Upc; 
delete from skus where skuValue = @Sku; 
set @Sku = 0; 

#select @shipping,@reprice; 


ELSE IF(choice = 'five') then 
select min(price) into @minimumprice from prices where upc= @Upc; 
update revised_price set price = @minimumprice where upc = @Upc; 
end if; 
end if; 
set @upclen = @upclen-1; 
delete from upcs where upcValue = @Upc; 
set @Upc = 0; 
end while; 
drop table upcs; 
drop table skus; 

END 

试试看以上码。

你做了

select min(price) into @minimumprice from prices where upc= @Upc group by upc; 

所以它会产生多行,而不是说你必须尝试

select min(price) into @minimumprice from prices where upc= @Upc ; 

希望这将有助于。

相关问题