Merge table into another table : Merge « Table « Oracle PL/SQL Tutorial






SQL> create table student_emails_ext
  2   (firstname    varchar(40),
  3    lastname     varchar(40),
  4    email        varchar(80) );

Table created.

SQL>
SQL> create table student_emails
  2  as select * from student_emails_ext
  3     where 0=1
  4  /

Table created.

SQL>
SQL>
SQL> merge into student_emails s
  2  using (select * from student_emails_ext) e
  3  on (s.firstname = e.firstname and s.lastname = e.lastname)
  4  when matched then
  5       update set s.email = e.email
  6  when not matched then
  7       insert (s.firstname, s.lastname, s.email)
  8       values(e.firstname , e.lastname, e.email);

0 rows merged.

SQL>
SQL> drop table student_emails_ext;

Table dropped.

SQL> drop table student_emails;

Table dropped.








6.5.Merge
6.5.1.Merge table
6.5.2.MERGE INTO
6.5.3.Merge with match
6.5.4.Merge table into another table
6.5.5.Merge two tables and map columns
6.5.6.Merge two tables when matched or not matched
6.5.7.Merge two tables with update