如下题 请经常写存储过程 懂数据库Oracle 或者你知道如何写都帮帮我
更新khexpinfo表的历史数据customer_id 的值,根据khexpInfo表的id与centerMaterialuseDetail表export_Uid关联,--centerMaterialuseDetail表的batchinfoUId与Batchinfo表的fuid关联,得到customer_id--用distinct关键字,如果结果记录数大于1则不需要处理,--否则就将khexinfo表的customer_id更新为所查出的customer_Id值
-- 先根据khexpinfo的id查询,若记录数大于1则不执行第2条更新语句,否则执行第2条语句更新语句select distinct b.customer_id from centermaterialusedetail c ,batchinfo b where c.export_uid='154461' and c.batchinfo_uid=b.fuid;
update khexpinfo set customer_id=(select distinct b.customer_id from centermaterialusedetail c ,batchinfo b where c.export_uid='154461' and c.batchinfo_uid=b.fuid) where id=154461;
我这样只能一条一条更新,谁会写歌存储过程 ,循环帮我更新,一条一条更新真的不现实啊
人气:378 ℃ 时间:2019-10-10 08:12:17
解答
create procedure test is
cursor custom_list is
select id from khexpinfo;
custom_dic custom_list%ROWTYPE;
my_custom_id in number(20);
begin
for custom_dic in custom_list loop
begin
select distinctb.customer_id into my_custom_id from centermaterialusedetail c ,batchinfo b where c.export_uid=custom_dic.id and c.batchinfo_uid=b.fuid;
update khexpinfo set customer_id=my_custom_id where id=custom_dic.id;
exception when others then
my_custom_id:=0;
end;
end loop;
commit;
end;
推荐
- 1/2+1/6+1/12+1/20+1/30用简便算法
- 一个圆柱的底面半径是2厘米,高是4厘米,他的侧面积是多少,表面积是多少
- depend on,depend upon 有啥区别
- 用至少4个成语造一个句子
- 举出一个反例证明:“如果两个三角形的三个角分别相等,且有两条边也相等,那么这两个三角形全等”为假命题
- 想,恨,忍,真,我,爱,情,你,没,世,今,一,在,活,生,为,乐,有,好,快,过,不.
- Actually I what all don't understand中文是什么意思
- 关于双引号的用法
猜你喜欢