The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.
Thanks for the question, Peyman.
Asked: November 09, 2017 - 3:02 pm UTC
Last updated: November 10, 2017 - 12:43 am UTC
Version: 11.2.0.2.0
Viewed 10K+ times! This question is
create table table_1 (c1 varchar2(100), c2 varchar2(100));
merge into table_1 tb using (select 'c1 value' as c1, 'c2 value' as c2 from dual where 1=2) v on (tb.c1=v.c1) when matched then update set tb.c2=v.c2 when not matched then insert (c1,c2) values(v.c1, v.c2);
select * from table_1;
SQL> @ver BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production PL/SQL Release 11.2.0.4.0 - Production CORE 11.2.0.4.0 Production TNS for 64-bit Windows: Version 11.2.0.4.0 - Production NLSRTL Version 11.2.0.4.0 - Production SQL> create table t (c1 varchar2(100), c2 varchar2(100)); Table created. SQL> SQL> SQL> merge into t tb 2 using (select 'c1 value' as c1, 'c2 value' as c2 from dual where 1=2) v 3 on (tb.c1=v.c1) 4 when matched then update set tb.c2=v.c2 5 when not matched then insert (c1,c2) values(v.c1, v.c2); 0 rows merged.
The Oracle documentation contains a complete SQL reference.