Oracle merge into delete語法
merge into也有delete語法。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
模擬實驗:
drop table test1 purge;
drop table test2 purge;create table test1(id number,name varchar2(10));
create table test2(id number,name varchar2(10));
insert into test1 values(1,'a');
insert into test1 values(2,'b');
insert into test1 values(3,'b');
insert into test1 values(4,'b');
insert into test1 values(5,'c');
insert into test1 values(6,'d');
insert into test1 values(7,'e');
insert into test2 values(1,'aa');
insert into test2 values(2,'aa');
insert into test2 values(3,'bb');
create index ind_t1_id on test1(id);
create index ind_t2_id on test2(id);
commit;
SQL> select * from test1;
ID NAME
---------- ----------
1 a
2 b
3 b
4 b
5 c
6 d
7 e
SQL> select * from test2;
ID NAME
---------- ----------
1 aa
2 aa
3 bb
merge into test1 t1
using (select id from test2 t2 where t2.name = 'aa') t2
on (t1.id = t2.id)
when matched then
update set t1.name = t1.name
delete where t1.id =t2.id;
commit;
SQL> select * from test1;
ID NAME
---------- ----------
3 b
4 b
5 c
6 d
7 e
需要注意的是:
SQL> merge into test1 t1using (select id from test2 t2 where t2.name = 'aa') t2
on (t1.id = t2.id)
when matched then
delete where t1.id =t2.id;
delete where t1.id =t2.id
*
第 5 行出現錯誤:
ORA-00905: 缺失關鍵字
必須要update語句
merge into test1 t1
using (select id from test2 t2 where t2.name = 'aa') t2
on (t1.id = t2.id)
when matched then
update set t1.name = t1.name --where只能出現一次,如果這裡使用了where,delete後面的where就無效了。
delete where t1.id =t2.id;
相關文章
- Oracle Merge語法Oracle
- oracle之merge語法(轉載)Oracle
- 用merge 語句代替 insert 和deletedelete
- Merge語法限制
- Sqlserver、oracle中Merge的使用方法,一個merge語句搞定多個Insert,Update,Delete操作SQLServerOracledelete
- mysql實現merge into語法MySql
- SQL 高階語法 MERGE INTOSQL
- 【SQL Server學習筆記】Delete 語句、Output 子句、Merge語句SQLServer筆記delete
- oracle中merge 語句使用Oracle
- MERGE語句語法檢查不嚴格
- SQL Server 2008 MERGE語法SQLServer
- MogDB/openGauss中merge的語法解析
- Sqlserver的merge into或delete語句堵塞select語句,鎖型別是LCK_M_ISSQLServerdelete型別
- mysql實現merge功能之DUPLICATE key UPDATE語法MySql
- MERGE新特性(UPDATE WHERE,DELETE WHERE,INSERT WHERE)delete
- oracle sequence語法Oracle
- Oracle With 語法 示例Oracle
- oracle partition by 語法Oracle
- Hive學習筆記 ---- 支援Update和Delete以及MergeHive筆記delete
- oracle merge into用法Oracle
- oracle_mergeOracle
- Oracle sql with 語句語法與例子OracleSQL
- oracle hint no_mergeOracle
- delete 大表解決辦法delete
- SQL Server的Merge —— 一步實現 insert,update,deleteSQLServerdelete
- oracle 10g裡,Merge語句的重大改進 ztOracle 10g
- 【轉載】oracle更新語法Oracle
- [SQL] Oracle基礎語法SQLOracle
- 建立Oracle包的語法Oracle
- Oracle常用sql語法集合OracleSQL
- ORACLE的基本語法(轉)Oracle
- Oracle物化檢視語法Oracle
- 【SQL】11 SQL DELETE 語句SQLdelete
- Sql Server系列:Delete語句SQLServerdelete
- FORALL執行DELETE語句delete
- ORACLE UPDATE 語句語法與效能分析Oracle
- oracle delete 分批刪除Oracledelete
- oracle中merge into用法解析Oracle