You are on page 1of 3

PARTITIONS

A single logical table can be split into a number of physically separate pieces
based on ranges of key values. Each of the parts of the table is called a partition.
TYPES

Range partitions

List partitions

Hash partitions

ADVANTAGES

Reducing downtime for scheduled maintenance, which allows maintenance


operations to be carried out on selected partitions while other partitions are
available to users.

Reducing downtime due to data failure, failure of a particular partition will


no way affect other partitions.

Example:

Creating a range-partitioned table


CREATE TABLE sales
( prod_id
NUMBER(6)
, cust_id
NUMBER
, time_id
DATE
, channel_id
CHAR(1)
, promo_id
NUMBER(6)
, quantity_sold NUMBER(3)
, amount_sold
NUMBER(10,2)
)
PARTITION BY RANGE (time_id)
( PARTITION sales_q1_2006 VALUES
yyyy'))
TABLESPACE tsa
, PARTITION sales_q2_2006 VALUES
yyyy'))
TABLESPACE tsb
, PARTITION sales_q3_2006 VALUES
yyyy'))
TABLESPACE tsc
, PARTITION sales_q4_2006 VALUES
yyyy'))
TABLESPACE tsd
);

LESS THAN (TO_DATE('01-APR-2006','dd-MONLESS THAN (TO_DATE('01-JUL-2006','dd-MONLESS THAN (TO_DATE('01-OCT-2006','dd-MONLESS THAN (TO_DATE('01-JAN-2007','dd-MON-

Creating a list-partitioned table


CREATE TABLE q1_sales_by_region
(deptno number,
deptname varchar2(20),
quarterly_sales number(10, 2),
state varchar2(2))
PARTITION BY LIST (state)
(PARTITION q1_northwest VALUES ('OR', 'WA'),
PARTITION q1_southwest VALUES ('AZ', 'UT', 'NM'),
PARTITION q1_northeast VALUES ('NY', 'VM', 'NJ'),
PARTITION q1_southeast VALUES ('FL', 'GA'),
PARTITION q1_northcentral VALUES ('SD', 'WI'),
PARTITION q1_southcentral VALUES ('OK', 'TX'));

Hash partitioning
Hash partitioning is a partitioning technique where a hash key is used to
distribute rows evenly across the different partitions (sub-tables). This is
typically used where ranges aren't appropriate, i.e. employee number,
productID, etc.
create table emp2 (
empno number(4),
ename varchar2(30),
sal
number
)
partition by hash(empno) (
partition e1 tablespace emp1,
partition e2 tablespace emp2,
partition e3 tablespace emp3,
partition e4 tablespace emp4
);
Materialized View
A materialized view is a database object that contains the results of a query. It is also called
as snapshot.
When creating a materialized view, you have the option of specifying whether the refresh
occurs ON DEMAND or ON COMMIT. In the case of ON COMMIT, the materialized view is
changed every time a transaction commits, thus ensuring that the materialized view always
contains the latest data. Alternatively, you can control the time when refresh of the
materialized views occurs by specifying ON DEMAND. In the case of ON DEMAND
materialized views, the refresh can be performed with refresh methods provided in either
the DBMS_SYNC_REFRESH or the DBMS_MVIEW packages

ON COMMIT

create materialized view log on t ;


create materialized view mv
REFRESH FAST ON COMMIT
as select * from t
;

ON DEMAND
create materialized view mv
REFRESH ON DEMAND
as select * from t
;
REFRESH MECHANISM
REFRESH COMPLETE
REFRESH FAST

OPERATIONS
On demand:- manual, schedule
On commit:- automatic

REFRESH FORCE (COMPLETE and FAST) --- but in case of fast materialized base table
should have mviewlog

PLSQL:
Basics :
What is a block and block structure (declaration, execution, exception )

You might also like