表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。有幾條重復資料,“-”后面就自動添加到幾
uj5u.com熱心網友回復:
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;
uj5u.com熱心網友回復:
“insert into .... value....”這里寫增加陳述句嗎?insert into A(b,c,d) values('','','')?uj5u.com熱心網友回復:
不寫,那是我寫給你理解的,你把Insert into...刪掉就是還有后面的Value
uj5u.com熱心網友回復:
if inserting thenselect 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
這樣就可以了么
uj5u.com熱心網友回復:
就這樣uj5u.com熱心網友回復:
i 代指是什么uj5u.com熱心網友回復:
:new.b:=:new.b||'-'||i; 這句話你看不出來i是什么嗎轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/55478.html
標籤:開發
上一篇:oracle資料庫出問題
下一篇:觸發器的基礎知識
