declare
vs_town_name varchar2(200);
vs_town_code varchar2(20);
vs_first_name varchar2(200);
vs_home_address varchar2(200);
vs_identity_code varchar2(30);
vs_contact_phone varchar2(50);
vn_identity_kind number;cursor get_user1 is
select user_id,customer_id,service_id,service_kind,source_id,apply_start_date,service_favour_id,service_group_id,serving_status,if_valid
from bb_service_relation_t 
where (service_kind = 8 or service_kind = 9);begin  delete from tb_czmx_t;
 
 commit;
 
 --1获取town_name信息
 
 for cur_user1 in get_user1 loop
 
  begin
  
   select town_code
   into :vs_town_code
   from bb_service_town_info_t 
   where user_id = cur_user1.user_id;
   exception
when others then
vn_town_code:=null;
    end;
    
    begin
    
    select town_name
    into :vs_town_name
    from bb_town_info_t
    where town_code=vs_town_code;
    exception
when others then
vs_town_name:=null;
     
    end;
    
    begin 
    
    select first_name,indentity_kind,identity_code,home_address,contact_phone
    into :vs_first_name,:vn_identity_kind,:vs_identity_code,:vs_home_address,:vs_contact_phone
    from bb_customer_info_t
    where customer_id = cur_user1.customer_id;
    exception
when others then
vs_first_name:=null;
        vn_identity_kind:=-1;
        vs_identity_code:=null;
        vs_home_address:=null;
        vs_contact_phone:=null;
    end;
    insert into tb_czmx_t(user_id,service_id,service_kind,apply_start_date,first_name,town_name,identity_kind,identity_code,home_address,contact_phone,customer_id,town_code)
     values(cur_user1.user_id,cur_user1.service_id,cur_user1.service_kind,cur_user1.apply_start_date,vs_first_name,vs_town_name,vn_identity_kind,vs_identity_code,vs_home_address,vs_contact_phone,cur_user1.customer_id,vs_town_code);
     commit;
     end loop;
    end;在运行时老是提示ora-01008并非所有变量都已关联的错误 请帮忙解决

解决方案 »

  1.   

    into :vs_first_name,:vn_identity_kind,:vs_identity_code,:vs_home_address,:vs_contact_phone
    改为
    into vs_first_name,vn_identity_kind,vs_identity_code,vs_home_address,vs_contact_phone
      

  2.   

    还是不行 老有这个ora-01008并非所有变量都已关联错误
      

  3.   

    过程里的变量不需要":"
    另外给老兄提点建议,不要每个操作都一个commit,最好在最后来一个commit,这样能保持事务的完整性,如果你的删除语句执行成功,而后面的插入失败,或者说循环中的部分成功,启不是数据完整性遭到破坏?!