3 回答

TA貢獻1796條經(jīng)驗 獲得超7個贊
begin insert into t (mykey, mystuff) values ('X', 123);exception when dup_val_on_index then update t set mystuff = 123 where mykey = 'X';end;

TA貢獻1815條經(jīng)驗 獲得超6個贊
這個合并語句將數(shù)據(jù)合并到兩個表之間。使用DUAL允許我們使用這個命令。請注意,這不受并發(fā)訪問的保護。
create or replace
procedure ups(xa number)
as
begin
merge into mergetest m using dual on (a = xa)
when not matched then insert (a,b) values (xa,1)
when matched then update set b = b+1;
end ups;
/
drop table mergetest;
create table mergetest(a number, b number);
call ups(10);
call ups(10);
call ups(20);
select * from mergetest;
A B
---------------------- ----------------------
10 2
20 1
添加回答
舉報