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

Home
Oracle PL / SQL
1.Aggregate Functions
2.Analytical Functions
3.Char Functions
4.Constraints
5.Conversion Functions
6.Cursor
7.Data Type
8.Date Timezone
9.Hierarchical Query
10.Index
11.Insert Delete Update
12.Large Objects
13.Numeric Math Functions
14.Object Oriented Database
15.PL SQL
16.Regular Expressions
17.Report Column Page
18.Result Set
19.Select Query
20.Sequence
21.SQL Plus
22.Stored Procedure Function
23.Subquery
24.System Packages
25.System Tables Views
26.Table
27.Table Joins
28.Trigger
29.User Previliege
30.View
31.XML
Oracle PL / SQL » Table » Merge 
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_exte
  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);

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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.