题目
如下题 请经常写存储过程 懂数据库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;
我这样只能一条一条更新,谁会写歌存储过程 ,循环帮我更新,一条一条更新真的不现实啊
更新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;
我这样只能一条一条更新,谁会写歌存储过程 ,循环帮我更新,一条一条更新真的不现实啊
提问时间:2020-11-27
答案
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 distinct b.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;
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 distinct b.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;
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1无独有偶式的成语
- 2与生态系统自我调节能力大小有关的主要因素是( ) A.生态系统的无机环境 B.生态系统的气候环境 C.生态系统的成分 D.生态系统的地理位置
- 3羲怎么读是多音字吗
- 4已知x²-x-2=0 求 (x-1)²+x-1
- 5eq什么意思
- 6( )÷8=0.75= 几分之三 = 几分之九 = 二十分之几 0.5平方米=( )平方分米 25立方分米=( )立方米
- 7光线通过透镜经过两次折射为什么是错的?
- 8一个质量为m=2Kg的物体,在几个恒力作用下处于静止状态,现在撤掉其中一个竖直向上的恒力F.已知F=2N.假设其他恒力保持不变,这个物体将怎样运动?
- 9600字与文学和书有关的作文
- 10用23除46与15的积 商是多少
热门考点