我现在使用merge into
声明,但它不符合要求。目前这样的代码......Oracle 11g - 如何在合并语句中执行多行?
create or replace procedure
mv_data
is
begin
merge into WORK w
using (select * from IF_WORK where batch = 0) i
on (w.token in (select token from IF_WORK where batch = 0))
when matched then
update set
w.area = i.area
, w.cust_id = i.cust_id
, w.status = i.status
, w.changed = sysdate
where w.token = i.token
-- I want to put "update IF_WORK set batch = 1 where work_id = i.work_id" here. Exception handling also.
when not matched then
insert
(
token, area, cust_id, status)
values
(i.token, i.area, i.cust_id, i.status)
-- I want to put "update IF_WORK set batch = 1 where work_id = i.work_id" here. Exception handling also.
;
update IF_WORK set batch = 1;
commit;
exception
when others then rollback;
end;
,并遵循什么我关心...
- 在当前的代码,它运行
for
环比更新所有。需要个人控制。 (我必须更新IF_WORK表,只有成功数据) exception
声明的位置。我想回滚或提交每一行,而不是全部。但是,现在它将全部回滚。
所以我试图将代码更改为一个merge
程序和程序,它处理单行。但我知道不能使用when matched then
的程序。
我该如何执行此操作?有没有好的陈述/方法? 谢谢。
P.S
因为我已经和Java一起工作了很长时间,所以我提供的代码看起来像Java中的后续代码。
/* This is something I wanted
public static void main(String[] args) {
List<String> aList = new ArrayList<String>();
for(String s : aList){
try{
* INSERT data !!! *
}catch(Exception e) {
* UPDATE data !!! *
}
}
}
*/
// Something I implemented for now
public static void main(String[] args) {
List<String> aList = new ArrayList<String>();
try{
for(String s : aList){
* INSERT data !!! *
}
}catch(Exception e) {
* UPDATE all !!! *
}
}
感谢。这非常有帮助。我把过程放在'loop'里面的'begin〜end;'块中,并把异常声明放到那里。所以我可以通过行单元处理异常。再次感谢:D –