表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。有几条重复数据,“-”后面就自动添加到几
调试欢乐多
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;
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这样就可以了么