表A,有列 a:主键,VARCHAR2(10),b:VARCHAR2(50),c:VARCHAR2(50),d:VARCHAR2(50);向表导入Execl表数据5条,其中3条b列数据一样。问:利用Oracle触发器,让b列的重复数据不再重复,有一样的时候,在后面自动添加-1、-2、-3······。例如:b列:123、123、111、123、1224。触发器触发后:123-1、123-2、111、123-3、1224。有几条重复数据,“-”后面就自动添加到几

解决方案 »

  1.   

    if inserting then
        select count(*) into i from table_a A where substr(A.b,0,length(:new.b))=:new.b;
        if i=0 then
          insert into ....
          value....
        else
          i=i+1;
          :new.b:=:new.b||'-'||i;
          insert into....
          value....
      end if;
      

  2.   

    “insert into .... value....”这里写增加语句吗?insert into A(b,c,d) values('','','')?
      

  3.   

    不写,那是我写给你理解的,你把Insert into...删掉就是还有后面的Value
      

  4.   

    if inserting then
        select count(*) into i from table_a A where substr(A.b,0,length(:new.b))=:new.b;
        if i=0 then
          
        else
          i=i+1;
          :new.b:=:new.b||'-'||i;
          
      end if
    end这样就可以了么
      

  5.   

     :new.b:=:new.b||'-'||i; 这句话你看不出来i是什么吗