mysql查询游标_数据库查询,游标。

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;

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值