You are on page 1of 25

3

A data warehouse is a collection of data designed to support business-management decision making. Data
warehouses contain a wide variety of data, such as sales data, customer data, payroll, accounting, and
personnel data, which presents a coherent picture of business conditions at a single point in time.

4
5
6
7
Creating and altering tables is discussed in more detail later in the course.

8
If a default value was specified for the hire_date column when the table was created, Oracle assigns the
default value to the column. However, if no default value was specified, Oracle assigns a null value.

9
10
11
12
create table copy_emp as (Select * from employees where department_id > 100);
select * from copy_emp;
update copy_emp
set last_name = 'Cotton'
where employee_id = 205;
select * from copy_emp;
MERGE INTO copy_emp c USING employees e
ON (c.employee_id = e.employee_id)
WHEN MATCHED THEN UPDATE
SET
c.last_name = e.last_name,
c.department_id = e.department_id
WHEN NOT MATCHED THEN INSERT
VALUES (e.employee_id, e.first_name, e.last_name, e.email, e.phone_number, e.hire_date, e.job_id,
e.salary, e.commission_pct, e.manager_id, e.department_id, e.bonus);
select * from copy_emp;
drop table copy_emp;

13
14
15
16
17
18
Note: there are times when the WHEN clause is not required, see example on next slide.

19
For more detailed examples including the use of FIRST and ELSE, visit
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9014.htm#i2125362

20
This multi-table insert, will retrieve the rows from the SELECT statement, and INSERT the rows into both the
my_employees and copy_my_employees table.

INSERT ALL requires a SELECT statement in order to run. We can, however, use the dummy table DUAL to perform
multiple INSERT statements into a single table – for example:

INSERT ALL
INTO copy_employees
(employee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary)
VALUES
(304,'James','Parrot', 'jparrot', '912-699-4656', '15/Jul/2017', 'IT_PROG',4200)
INTO copy_employees
(employee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary)
VALUES
(305,'Rebecca','Graham', 'rgraham', '480-678-4259', '15/Jun/2017', 'IT_PROG',4200)
SELECT * FROM dual;

21
This multi-table insert uses the WHEN condition. If a row from the SELECT statement matches the criteria of
the WHEN condition, the row is added to the table in the INTO clause.
Note: this example is used to demonstrate a real-word use for multi-table inserts, but as tables do not exist
this query will not run in APEX.

22
23
24

You might also like