0

在下面的代码中,第一个插入语句是,

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;
4

1 回答 1

1

为此我收到空值插入错误。是的,这是正确的。

但它在块的语句下方停止执行。

异常导致流程转到异常处理程序部分。这是程序块的结尾。因此处理异常后停止处理。这是标准的。所以实际上,您错误地为您的问题命名,因为这是处理异常的正确方法。关键是要保持事务的酸度。如果程序的第一部分失败,为什么要继续处理?

尽管将其描述为正确的方式,但我觉得我必须说仅通过使用 DBMS_OUTPUT 来“处理”异常是非常糟糕的做法。这在生产代码中不起作用,因为调用 progarm 不会知道发生了异常。您的过程需要记录错误,然后重新引发异常。其他任何事情都只是自找麻烦。

于 2013-06-28T09:10:11.727 回答