create or replace procedure pro_temp_customer as
  cursor c is select * from TEMP_CRM_CUSTOMER;
begin
  for rc in c loop
是想在这个temp_crm_customer中为主键加一个序列每次执行完存贮过程想用truncate   table   temp_crm_customer清除表内容,之后每天都会往表中新增内容,这样这个主键就部能重复,我自己建立了一个序列不知道怎么在这里使用呢求解答      if rc.point = 'U' then
         update crm_customer a set a.city='',a.area='',a.district=''
            where a.bankcard in (select temp_crm_customer.bankcard from crm_customer,temp_crm_customer
             where crm_customer.address != temp_crm_customer.address and temp_crm_customer.point = 'U' and
             temp_crm_customer.bankcard = crm_customer.bankcard);
       
      end if;
  end loop;
end;

解决方案 »

  1.   


    create or replace procedure pro_temp_customer as
      cursor c is select * from TEMP_CRM_CUSTOMER;
    begin
      for rc in c loop
    --是想在这个temp_crm_customer中为主键加一个序列每次执行完存贮过程想用
    --truncate table temp_crm_customer清除表内容,之后每天都会往表中新增内容,
    --这样这个主键就部能重复,我自己建立了一个序列不知道怎么在这里使用呢求解答--1、主键用序列产生,要想truncate table之后重复使用序列,
    --那么你truncate table 之后再重新drop sequence ,再创建一次,下次就是用1开始的了啊
      if rc.point = 'U' then
      update crm_customer a set a.city='',a.area='',a.district=''
      where a.bankcard in (select temp_crm_customer.bankcard from crm_customer,temp_crm_customer
      where crm_customer.address != temp_crm_customer.address and temp_crm_customer.point = 'U' and
      temp_crm_customer.bankcard = crm_customer.bankcard);
        
      end if;
      end loop;
      --truncate table 
      execute immediate 'truncate table TEMP_CRM_CUSTOMER';
      --drop sequence
      execute immediate 'drop sequence sequence_name';
      --rebuild sequence
      execute immediate 'create or replace sequence sequence_name start with 1 incement by 1';
    end;
      

  2.   

    insert into TEMP_CRM_CUSTOMER(sequence.nextval,'***','***',...);
    commitcreate or replace procedure pro_temp_customer as
      cursor c is select * from TEMP_CRM_CUSTOMER;
    begin
      for rc in c loop
        if rc.point = 'U' then
           update crm_customer a set a.city='',a.area='',a.district=''
          where a.bankcard in (select temp_crm_customer.bankcard from crm_customer,temp_crm_customer
           where crm_customer.address != temp_crm_customer.address and temp_crm_customer.point = 'U' and
           temp_crm_customer.bankcard = crm_customer.bankcard);    
           end if;
      end loop;
      execute immediate 'truncate table TEMP_CRM_CUSTOMER'; 
    end;