How to handle exception and execute remaining stat

2019-03-04 22:45发布

Please find the below block.

for i in 1..acd.count loop

insert into customer_account_mapping select customerid,upper(pcd(i)),upper(acd(i)),cost from customer_master where customername=customer_name and concat(upper(pcd(i)),upper(acd(i))) not in (select concat(upper(pcode),upper(acode)) from customer_account_mapping);

insert into user_permissions select distinct user_id,sales_person_name,sales_mgr_name,upper(pcd(i)),upper(acd(i)) from user_permissions where sales_person_name=sales_person and concat(upper(pcd(i)),upper(acd(i))) not in (select concat(upper(pcode),upper(acode)) from user_permissions) and rownum<2 ;
commit;
end loop;

If error occurred in first insert statement how to handle it and execute second insert statement.

2条回答
倾城 Initia
2楼-- · 2019-03-04 23:36
EXCEPTION  -- exception handlers begin



 WHEN exception type  -- handles 'division by zero' error
           ...

 WHEN OTHERS THEN  -- handles all other errors
      ROLLBACK;

END;

Put this code block after first insert statement.

查看更多
我想做一个坏孩纸
3楼-- · 2019-03-04 23:49

wrap the lines with begin ... end ... exception it's like try / catch

for i in 1..acd.count loop

begin 
   insert into customer_account_mapping select customerid,upper(pcd(i)),upper(acd(i)),cost from customer_master where customername=customer_name and concat(upper(pcd(i)),upper(acd(i))) not in (select concat(upper(pcode),upper(acode)) from customer_account_mapping);
exception when others then 
   -- handle the exception
end;

insert into user_permissions select distinct user_id,sales_person_name,sales_mgr_name,upper(pcd(i)),upper(acd(i)) from user_permissions where sales_person_name=sales_person and concat(upper(pcd(i)),upper(acd(i))) not in (select concat(upper(pcode),upper(acode)) from user_permissions) and rownum<2 ;
commit;
end loop;
查看更多
登录 后发表回答