Thursday, February 8, 2018

What is a Partition in Oracle and Type of Partitions , Range Partition







 /*****************************************************************************
ORACLE PARTITIONS AND TYPES.

1) Range Partitioning
2) LIST Partitioning
3) HASH Partitioning
4) Composite RANGE-HASH Partitioning
5) Composite RANGE-LIST Partitioning
******************************************************************************/


drop table emp_part;

CREATE TABLE emp_part
(
    EMPNO    NUMBER(4,0) ,
    ENAME    VARCHAR2(10 ),
    JOB      VARCHAR2(9 ),
    MGR      NUMBER(4,0),
    HIREDATE DATE,
    SAL      NUMBER(7,2),
    COMM     NUMBER(7,2),
    DEPTNO   NUMBER(2,0)
  )PARTITION BY RANGE (sal)
           INTERVAL  (1000)
          (
     PARTITION p1 VALUES LESS THAN (1000)   ,
     PARTITION p2 VALUES LESS THAN (2000)  ,
     PARTITION p3 VALUES LESS THAN (3000)  ,
     PARTITION p4 VALUES LESS THAN (4000)
     )ENABLE ROW MOVEMENT ;
   
 select * from emp_part PARTITION(P2); --where sal>4000;
 ;

BEGIN
 DBMS_STATS.gather_table_stats('SDEV', 'EMP_PART');
 END;
 /
 insert into emp_part select * from emp;
 commit;

  select * from emp_part PARTITION(p3);



drop table emp_RANGE_DT;
 CREATE TABLE emp_RANGE_DT
 (
    EMPNO    NUMBER(4,0) ,
    ENAME    VARCHAR2(10 ),
    JOB      VARCHAR2(9 ),
    MGR      NUMBER(4,0),
    HIREDATE DATE,
    SAL      NUMBER(7,2),
    COMM     NUMBER(7,2),
    DEPTNO   NUMBER(2,0)
  )
 PARTITION BY RANGE (HIREDATE)
(Partition P1 values less than (TO_DATE ('01-JAN-1980','dd-MON-yyyy')),
Partition P2 values less than (TO_DATE ('01-JAN-1985','dd-MON-yyyy')),
Partition P3 values less than (TO_DATE ('01-JAN-1990','dd-MON-yyyy')),
Partition P4 values less than (TO_DATE ('01-JAN-2000','dd-MON-yyyy'))
) ENABLE ROW MOVEMENT;;

 insert into emp_RANGE_DT select * from emp;
 commit;

BEGIN
 DBMS_STATS.gather_table_stats('SDEV', 'EMP_RANGE_DT');
END;
 /
 

/* ==========================================================================*/

DROP TABLE EMP_LIST;

CREATE TABLE EMP_LIST
  (
    EMPNO    NUMBER(4,0) ,
    ENAME    VARCHAR2(10 ),
    JOB      VARCHAR2(9 ),
    MGR      NUMBER(4,0),
    HIREDATE DATE,
    SAL      NUMBER(7,2),
    COMM     NUMBER(7,2),
    DEPTNO   NUMBER(2,0)
  )
   PARTITION BY LIST (DEPTNO)
      (
       PARTITION P1 VALUES ('10'),
       PARTITION P2 VALUES ('20'),
       PARTITION P3 VALUES ('30'),
       PARTITION P4 VALUES ('40')
     ) ENABLE ROW MOVEMENT;
 
INSERT INTO EMP_LIST SELECT * FROM EMP; 
COMMIT;

BEGIN
 DBMS_STATS.gather_table_stats('SDEV', 'EMP_LIST');
END;
 /
select * from EMP_LIST where deptno=20;

select * from emp where deptno=10;

No comments:

Post a Comment