所有的MIS系統都存在一個同樣的需求
更新
MERGE INTO [your table
USING
(
[write your query here]
)[rename your query
ON
([conditional expression here] AND [
WHEN
MATCHED
THEN
[here you can execute some update sql or something else ]
WHEN
NOT MATCHED
THEN
[execute something else here ! ]
下面是實例
假設一個student表 有這種需求
如果學生ID不存在 則插入學生信息
select
S_ID S_NAME S_AGE
select
ID NAME TEL ADDRESS
merge into student s
using
(
select id
on
(s
when matched
then update set s_name=x
when not matched
then insert
(s_id
values
(x
commit;
最終結果
select
S_ID S_NAME S_AGE
注意到 MERGE 語句在最後的
From:http://tw.wingwit.com/Article/program/Oracle/201311/16764.html