1把test1中,价格高于2000,产地是中国,杭州的产品信息,放到新建表test1_temp中,2并且要求test1中的category替换成test2中的categoryname,3最后商品价格高于2000的下调5%麻烦高手...
1把test1中,价格高于2000,产地是中国,杭州的产品信息,放到新建表test1_temp中,
2并且要求test1中的category替换成test2中的categoryname,
3最后商品价格高于2000的下调5%
麻烦高手,帮我检查下我写的代码,哪里有错误。
declarecursor yb1 is select * from test1 where productprice>2000 and origin in('中国','杭州');
cur_bl test1%rowtype;
cursor cur_cat is select * from test2;cur_cat2 test2%rowtype;
begin
--把符合要求的数据放进表test1_tmp open yb1;
loop
fetch yb1 into cur_b1;
exit when yb1%notfound;
insert into test1_tmp(productid,productname,productprice,quantity,category,desperation,origin)
values(yb1.productid,yb1.productname,yb1.productprice,yb1.quantity,yb1.category,yb1.desperation,yb1.origin);
commit;
--test1中的category替换成test2中的categorynameopen cur_cat;
loop
fetch cur_cat into cur_cat2;
exit when cur_cat2%notfound;
update test1_tmp set test1_tmp.category=cur_cat2.categoryname where test1_tmp.category=cur_cat2.categoryid;
--更改价格
update test1_tmp set test1_tmp.productprice=test1_tmp.productprice*0.95 where test1_tmp.productprice>2000;
commit;
end loop;
end;
展开