2013-06-28 70 views
0

請找到下面的塊。如何處理異常並執行剩餘的語句?

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; 

如果在第一個插入語句中發生錯誤,如何處理它並執行第二個插入語句。

+0

這將是有益的格式化你的代碼,所以它不是一個長線的線。 –

+0

每次插入後提交通常都是不好的做法。你爲什麼需要這樣做? – OldProgrammer

回答

0
EXCEPTION -- exception handlers begin 



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

WHEN OTHERS THEN -- handles all other errors 
     ROLLBACK; 

END; 

把這個代碼塊放在第一個插入語句之後。

+0

不行不通。 – user2523846

2

纏上begin ... end ... exception它就像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; 
相關問題