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






Merge table into another table

 

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.

   
  








Related examples in the same category

1.Merge two tables and map columns
2.Merge two tables when matched or not matched
3.Merge two tables with update