0% found this document useful (0 votes)
12 views3 pages

Oracle (2PM) 2

The document provides an overview of partitioning in Oracle databases, explaining its purpose in managing large data tables by dividing them into smaller, more manageable units. It details three types of partitions: range, list, and hash, including their syntax and examples for creating and querying partitioned tables. Additionally, it covers how to add or drop partitions and how to check if a table is partitioned using data dictionaries.

Uploaded by

rohit1237363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Oracle (2PM) 2

The document provides an overview of partitioning in Oracle databases, explaining its purpose in managing large data tables by dividing them into smaller, more manageable units. It details three types of partitions: range, list, and hash, including their syntax and examples for creating and querying partitioned tables. Additionally, it covers how to add or drop partitions and how to check if a table is partitioned using data dictionaries.

Uploaded by

rohit1237363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

PARTITION TABLE:(06-12-2024)

================
- Generally partitions are created on very large scale data tables for
dividing into
small small units and each unit is called as "partition".
- By using partitions we can save searching time of oracle server.
- Oracle supports the following three types of partitions.those are,
1) Range partition
2) List partition
3) Hash partition
1) Range partition:
================
- created a partition table based on the particular range value.
syntax:
=======
create table <table name>(<column name1>
<datatype>[size],............................)
partition by range(key column)(partition <partition name1> values less than(value),
partition <partition name2> values less
than(value),.............................................);

EX:
SQL> CREATE TABLE TEST11(ENAME VARCHAR2(10),SAL NUMBER(8,2))
2 PARTITION BY RANGE(SAL)
3 (
4 PARTITION P1 VALUES LESS THAN(10000),
5 PARTITION P2 VALUES LESS THAN(15000),
6 PARTITION P3 VALUES LESS THAN(25000)
7 );

TESTING:
SQL> INSERT INTO TEST11 VALUES('SMITH',8500);
SQL> INSERT INTO TEST11 VALUES('JONES',22000);
SQL> INSERT INTO TEST11 VALUES('ALLEN',12000);
SQL> SELECT * FROM TEST11;

How to call a particular partition data from a table:


===========================================
syntax:
======
SELECT * FROM <TABLE NAME> PARTITION(PARTITION NAME);

EX:
SQL> SELECT * FROM TEST11 PARTITION(P1);
SQL> SELECT * FROM TEST11 PARTITION(P2);
SQL> SELECT * FROM TEST11 PARTITION(P3);

07-12-2024:
===========
2) List partition:
==============
- created a partition table based on the list of values.

syntax:
=======
create table <table name>(<column name1>
<datatype>[size],............................)
partition by list(key column)(partition <partition name1> values
(value1,value2,.....),
partition <partition name2> values
(value1,value2),.............................................
partition others values (default));

EX:
SQL> CREATE TABLE TEST22(CID NUMBER(4),CNAME VARCHAR2(10))
2 PARTITION BY LIST(CNAME)
3 (
4 PARTITION P1 VALUES('ORACLE','MYSQL'),
5 PARTITION P2 VALUES('JAVA','.NET','PYTHON'),
6 PARTITION OTHERS VALUES(DEFAULT)
7 );

TESTING:
SQL> INSERT INTO TEST22 VALUES(1,'ORACLE');
SQL> INSERT INTO TEST22 VALUES(2,'C');
SQL> INSERT INTO TEST22 VALUES(3,'JAVA');

Calling a particular partition:


=========================
SQL> SELECT * FROM TEST22 PARTITION(P1);

3) Hash partition:
===============
- created a partition table by the system as per user request.
- in this partition values are storing random.
syntax:
=======
create table <table name>(<column name1>
<datatype>[size],............................)
partition by hash(key column) partitions <number>;

EX:
SQL> CREATE TABLE TEST33(SNAME VARCHAR2(10),SFEE NUMBER(6,2))
2 PARTITION BY HASH(SFEE) PARTITIONS 5;

TESTING:
SQL> INSERT INTO TEST33 VALUES(1,2500);
SQL> INSERT INTO TEST33 VALUES(2,500);

Calling a particular partition from a table:


===================================
SQL> SELECT * FROM TEST33 PARTITION(SYS_P5875);

NOTE:
=====
-To view partitions of a specific table in oracle database then we use a
datadictionary
is "USER_TAB_PARTITIONS".

EX:
SQL> DESC USER_TAB_PARTITIONS;
SQL> SELECT PARTITION_NAME FROM USER_TAB_PARTITIONS WHERE TABLE_NAME='TEST33';

PARTITION_NAME
-----------------------------
SYS_P5872
SYS_P5873
SYS_P5874
SYS_P5875
SYS_P5876

How to add a new partition to an existing table:


========================================
syntax:
=======
ALTER TABLE <TABLE NAME> ADD PARTITION <PARTITION NAME> VALUES LESS THAN(VALUE);

EX:
SQL> ALTER TABLE TEST11 ADD PARTITION P4 VALUES LESS THAN(30000);

TESTING:
SQL> INSERT INTO TEST11 VALUES('WARD',29000);
SQL> SELECT * FROM TEST11 PARTITION(P4);

How to drop a partition from a table:


================================
syntax:
======
ALTER TABLE <TABLE NAME> DROP PARTITION <PARTITION NAME>;

EX:
SQL> ALTER TABLE TEST11 DROP PARTITION P4;

NOTE:
======
- To check a table is partitioned table or not in oracle then we use a
datadictionary
is "USER_TABLES".

EX:
SQL> DESC USER_TABLES;
SQL> SELECT PARTITIONED FROM USER_TABLES WHERE TABLE_NAME='EMP';

PAR
---
NO

SQL> SELECT PARTITIONED FROM USER_TABLES WHERE TABLE_NAME='TEST11';

PAR
---
YES

You might also like