首页 > 技术文章 > oracle declare

albert-think 2016-11-02 17:50 原文

declare
  l_cust_id     number(10) := 0;
  l_person_id   number(10) := 0;
begin
  DBMS_OUTPUT.ENABLE(buffer_size => null); --表示输出buffer不受限制
  for lr in (SELECT temp.customer_name, temp.assign_persion_name
               from CUSTOMER_ASSIGN_TEMP temp) loop
      --dbms_output.put_line(lr.customer_name||'|'||lr.assign_persion_name);
      begin
        select hz.party_id
          into l_cust_id
          from hz_parties hz
         where trim(hz.party_name) = trim(lr.customer_name)
           and rownum = 1;
        update CUSTOMER_ASSIGN_TEMP cust
           set cust.cust_party_id = l_cust_id where trim(cust.customer_name)=trim(lr.customer_name);
      exception
        when No_data_found then
          dbms_output.put_line(trim(lr.customer_name) || '-客户名称不正确');
      end;
       begin
        select emp.PERSON_ID
          into l_person_id
          from web_employees_v emp
         where emp.CHINESE_NAME = lr.assign_persion_name
           and rownum = 1;
        update CUSTOMER_ASSIGN_TEMP custp
           set custp.assign_persion_id = l_person_id where trim(custp.customer_name)=trim(lr.customer_name);
      exception
        when No_data_found then
          dbms_output.put_line(lr.assign_persion_name || '-人员名称不正确');
      end;
     commit;
    end loop;
  end;

----调用

declare
l_code varchar2(1000);
begin
    pro_syn_customer_ecp('Y',l_code);
dbms_output.put_line(l_code);
end;

推荐阅读