在下面的代码中,第一个插入语句是,
insert into customer_master select max(customerid)+1,customer_name from customer_master
where customer_name not in (select customername from customer_master);
为此获取空值插入错误。是的,这是对的。
但它正在阻止执行该块的语句。
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 ;
完整代码如下。
create or replace
procedure dashboard_addtion
(customer_name varchar2,pcd parray,acd aarray,sales_person varchar2,cost number)
IS
begin
insert into customer_master select max(customerid)+1,customer_name from customer_master
where customer_name not in (select customername from customer_master);
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;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (SQLERRM);
end;
答案 0 :(得分:1)
为此获取空值插入错误。是的,这是对的。
但它正在阻止执行该块的语句。
异常导致进程流程转到EXCEPTION处理程序部分。那是程序块的结束。因此处理异常后处理停止。这是标准的。所以事实上,你错误地标题了你的问题,因为这是处理异常的正确方法。重点是保留the ACIDity of the transaction。如果程序的第一部分失败,为什么还要继续处理呢?
虽然,我已经将这个描述为正确的方式,我觉得我必须说通过简单地使用DBMS_OUTPUT“处理”异常是非常糟糕的做法。这在生产代码中不起作用,因为调用progarm不会知道发生了异常。您的过程需要记录错误,然后重新引发异常。其他任何事情只是在寻找麻烦。