oracle 10g裡,Merge語句的重大改進 zt
1, 能嵌入delete語句
2, update, insert語句能嵌入where clause
3, update語句與insert語句,不必同時出現,是可選的(optional)
MERGE Statement Enhancements in Oracle Database 10g
Oracle 10g includes a number of amendments to the MERGE
statement making it more flexible.
Test Table
The following examples use the table defined below.
CREATE TABLE test1 AS SELECT * FROM all_objects WHERE 1=2;
Optional Clauses
The MATCHED
and NOT MATCHED
clauses are now optional making all of the following examples valid.
-- Both clauses present. MERGE INTO test1 a USING all_objects b ON (a.object_id = b.object_id) WHEN MATCHED THEN UPDATE SET a.status = b.status WHEN NOT MATCHED THEN INSERT (object_id, status) VALUES (b.object_id, b.status); -- No matched clause, insert only. MERGE INTO test1 a USING all_objects b ON (a.object_id = b.object_id) WHEN NOT MATCHED THEN INSERT (object_id, status) VALUES (b.object_id, b.status); -- No not-matched clause, update only. MERGE INTO test1 a USING all_objects b ON (a.object_id = b.object_id) WHEN MATCHED THEN UPDATE SET a.status = b.status;
Conditional Operations
Conditional inserts and updates are now possible by using a WHERE
clause on these statements.
-- Both clauses present. MERGE INTO test1 a USING all_objects b ON (a.object_id = b.object_id) WHEN MATCHED THEN UPDATE SET a.status = b.status WHERE b.status != 'VALID' WHEN NOT MATCHED THEN INSERT (object_id, status) VALUES (b.object_id, b.status) WHERE b.status != 'VALID'; -- No matched clause, insert only. MERGE INTO test1 a USING all_objects b ON (a.object_id = b.object_id) WHEN NOT MATCHED THEN INSERT (object_id, status) VALUES (b.object_id, b.status) WHERE b.status != 'VALID'; -- No not-matched clause, update only. MERGE INTO test1 a USING all_objects b ON (a.object_id = b.object_id) WHEN MATCHED THEN UPDATE SET a.status = b.status WHERE b.status != 'VALID';
DELETE Clause
An optional DELETE WHERE
clause can be used to clean up after a merge operation. Only those rows which match both the ON
clause and the DELETE WHERE
clause are deleted.
MERGE INTO test1 a USING all_objects b ON (a.object_id = b.object_id) WHEN MATCHED THEN UPDATE SET a.status = b.status WHERE b.status != 'VALID' DELETE WHERE (b.status = 'VALID');
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82387/viewspace-1016320/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle中merge 語句使用Oracle
- ORACLE SQL語句優化技術分析(zt)OracleSQL優化
- Merge into: Oracle中用一條SQL語句直接進行Insert/Update的操作(R1)OracleSQL
- oracle 10g merge命令的增強Oracle 10g
- Oracle Merge語法Oracle
- (zt) Oracle語句優化30個規則詳解Oracle優化
- MERGE語句語法檢查不嚴格
- 【SQL Server學習筆記】Delete 語句、Output 子句、Merge語句SQLServer筆記delete
- oracle 檢索最近10分鐘裡消耗IO最嚴重的前5條SQL語句OracleSQL
- merge語句導致的ORA錯誤分析
- 使用SQL MERGE語句組合表SQL
- Sqlserver、oracle中Merge的使用方法,一個merge語句搞定多個Insert,Update,Delete操作SQLServerOracledelete
- Oracle merge into delete語法Oracledelete
- [ZT] Oracle 10g RAC的相關概念Oracle 10g
- oracle 9i/10g merge 用法Oracle
- oracle 10g AWR介紹(ZT)Oracle 10g
- Oracle EXECUTE IMMEDIATE語句裡面的引號處理Oracle
- [zt] 基於索引的SQL語句優化索引SQL優化
- 用merge 語句代替 insert 和deletedelete
- oracle對非使用繫結變數的語句去重Oracle變數
- oracle的sql語句OracleSQL
- Sqlserver的merge into或delete語句堵塞select語句,鎖型別是LCK_M_ISSQLServerdelete型別
- oracle語句Oracle
- 轉:oracle 9i/10g merge 用法Oracle
- Wait Event Enhancements in Oracle 10g(zt)AIOracle 10g
- ORACLE 10G OCA 042 筆記(zt)Oracle 10g筆記
- Oracle Flashback (9i & 10g) [zt]Oracle
- SQL Server 2008中的新語句:MERGESQLServer
- 利用Oracle 10g SQL優化器(STA)優化語句Oracle 10gSQL優化
- Oracle 查詢並刪除重複記錄的SQL語句OracleSQL
- SQL語句效能調整原則(zt)SQL
- [zt] 使用snmp 監控 Oracle 10g(10.2.0.4) 時oracle 10g snmp的配置Oracle 10g
- oracle 10g ,11g 自動生成建立表空間的語句Oracle 10g
- Oracle Hints語句的用法Oracle
- Oracle的多表插入語句Oracle
- oracle的表分析語句Oracle
- 常用的oracle基本語句Oracle
- oracle的connect by語句Oracle