oracle裡的merge into用法

2021-06-08 23:47:21 字數 1438 閱讀 6494

1、根據表newproducts的product_id欄位是否匹配來updates表products的資訊:

sql> merge into products p

2 using newproducts np

3 on (p.product_id = np.product_id)

4 when matched then

5 update

6 set p.product_name = np.product_name,

7 p.category = np.category;

2、根據表newproducts來更新表products資料, 但必須欄位category也得同時匹配上:

sql> merge into products p

2 using newproducts np

3 on (p.product_id = np.product_id)

4 when matched then

5 update

6 set p.product_name = np.product_name

7 where p.category = np.category;

3、 oracle 10g現在支援在on條件中使用常量過濾謂詞. 舉個常量過濾謂詞例子on (1=0). 下面例子從源表插入行到表products, 不檢查這些行是否在表products中存在:

sql> merge into products p

2 using newproducts np

3 on (1=0)

4 when not matched then

5 insert

6 values (np.product_id, np.product_name, np.category)

7 where np.category = 'books'

sql> /

4、下面例子驗證delete子句. 我們從表newproducts中合併行到表products中, 但刪除category為electrncs的行.

sql> merge into products p

2 using newproducts np

3 on (p.product_id = np.product_id)

4 when matched then

5 update

6 set p.product_name = np.product_name,

7 p.category = np.category

8 delete where (p.category = 'electrncs')

9 when not matched then

10 insert

11 values (np.product_id, np.product_name, np.category)

sql> /

摘至:

oracle裡的判斷函式

乙個類似於判斷的函式.它就是decode.先來看看它的用法 decode 條件,值1,翻譯值1,值2,翻譯值2,值n,翻譯值n,預設值 它的意思也就是這樣 if 條件 值1 then return 翻譯值1 elsif 條件 值2 then return 翻譯值2 elsif 條件 值n then ...

oracle裡的extend詳解

擴充套件已知的陣列空間,例 declare type courselist is table of varchar2 10 courses courselist begin 初始化陣列元素,大小為3 courses courselist biol 4412 psyc 3112 anth 3001 為...

oracle裡的procedure和陣列 函式

create or replace procedure proname aa in varchar2,bb in integer,result out types.cursortype is v un date v u1 varchar2 1000 v u2 varchar2 1000 sqlmai...