CREATE TABLE SH.SALES_PT 
   (	PROD_ID NUMBER NOT NULL ENABLE, 
    	CUST_ID NUMBER NOT NULL ENABLE,
    	TIME_ID DATE NOT NULL ENABLE, 
    	CHANNEL_ID NUMBER NOT NULL ENABLE, 
    	PROMO_ID NUMBER NOT NULL ENABLE, 
    	QUANTITY_SOLD NUMBER(10,2) NOT NULL ENABLE, 
    	AMOUNT_SOLD NUMBER(10,2) NOT NULL ENABLE 
       )  
  PARTITION BY RANGE (TIME_ID) 
 (PARTITION ST_1995    VALUES LESS THAN (TO_DATE('19960101', 'YYYYMMDD')), 
  PARTITION ST_1996    VALUES LESS THAN (TO_DATE('19970101', 'YYYYMMDD')), 
  PARTITION ST_H1_1997 VALUES LESS THAN (TO_DATE('19970701', 'YYYYMMDD')), 
  PARTITION ST_H2_1997 VALUES LESS THAN (TO_DATE('19980101', 'YYYYMMDD')), 
  PARTITION ST_Q1_1998 VALUES LESS THAN (TO_DATE('19980401', 'YYYYMMDD')), 
  PARTITION ST_Q2_1998 VALUES LESS THAN (TO_DATE('19980701', 'YYYYMMDD')), 
  PARTITION ST_Q3_1998 VALUES LESS THAN (TO_DATE('19981001', 'YYYYMMDD')), 
  PARTITION ST_Q4_1998 VALUES LESS THAN (TO_DATE('19990101', 'YYYYMMDD')), 
  PARTITION ST_Q1_1999 VALUES LESS THAN (TO_DATE('19990401', 'YYYYMMDD')), 
  PARTITION ST_Q2_1999 VALUES LESS THAN (TO_DATE('19990701', 'YYYYMMDD')), 
  PARTITION ST_Q3_1999 VALUES LESS THAN (TO_DATE('19991001', 'YYYYMMDD')), 
  PARTITION ST_Q4_1999 VALUES LESS THAN (TO_DATE('20000101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2000 VALUES LESS THAN (TO_DATE('20000401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2000 VALUES LESS THAN (TO_DATE('20000701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2000 VALUES LESS THAN (TO_DATE('20001001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2000 VALUES LESS THAN (TO_DATE('20010101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2001 VALUES LESS THAN (TO_DATE('20010401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2001 VALUES LESS THAN (TO_DATE('20010701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2001 VALUES LESS THAN (TO_DATE('20011001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2001 VALUES LESS THAN (TO_DATE('20020101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2002 VALUES LESS THAN (TO_DATE('20020401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2002 VALUES LESS THAN (TO_DATE('20020701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2002 VALUES LESS THAN (TO_DATE('20021001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2002 VALUES LESS THAN (TO_DATE('20030101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2003 VALUES LESS THAN (TO_DATE('20030401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2003 VALUES LESS THAN (TO_DATE('20030701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2003 VALUES LESS THAN (TO_DATE('20031001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2003 VALUES LESS THAN (TO_DATE('20040101', 'YYYYMMDD')) 
)  ;
INSERT INTO SH.SALES_PT 
SELECT PROD_ID,
       CUST_ID,
       TIME_ID,
       CHANNEL_ID,
       PROMO_ID,
       QUANTITY_SOLD,
       AMOUNT_SOLD
  FROM SH.SALES;

COMMIT;

CREATE TABLE SH.SALES_ORDER_PT 
   (	PROD_ID NUMBER NOT NULL ENABLE, 
    	CUST_ID NUMBER NOT NULL ENABLE,
    	ORDER_DT DATE NOT NULL ENABLE,  
    	TIME_ID DATE NOT NULL ENABLE, 
    	CHANNEL_ID NUMBER NOT NULL ENABLE, 
    	PROMO_ID NUMBER NOT NULL ENABLE, 
    	QUANTITY_SOLD NUMBER(10,2) NOT NULL ENABLE, 
    	AMOUNT_SOLD NUMBER(10,2) NOT NULL ENABLE 
       )  
  PARTITION BY RANGE (TIME_ID) 
 (PARTITION ST_1995    VALUES LESS THAN (TO_DATE('19960101', 'YYYYMMDD')), 
  PARTITION ST_1996    VALUES LESS THAN (TO_DATE('19970101', 'YYYYMMDD')), 
  PARTITION ST_H1_1997 VALUES LESS THAN (TO_DATE('19970701', 'YYYYMMDD')), 
  PARTITION ST_H2_1997 VALUES LESS THAN (TO_DATE('19980101', 'YYYYMMDD')), 
  PARTITION ST_Q1_1998 VALUES LESS THAN (TO_DATE('19980401', 'YYYYMMDD')), 
  PARTITION ST_Q2_1998 VALUES LESS THAN (TO_DATE('19980701', 'YYYYMMDD')), 
  PARTITION ST_Q3_1998 VALUES LESS THAN (TO_DATE('19981001', 'YYYYMMDD')), 
  PARTITION ST_Q4_1998 VALUES LESS THAN (TO_DATE('19990101', 'YYYYMMDD')), 
  PARTITION ST_Q1_1999 VALUES LESS THAN (TO_DATE('19990401', 'YYYYMMDD')), 
  PARTITION ST_Q2_1999 VALUES LESS THAN (TO_DATE('19990701', 'YYYYMMDD')), 
  PARTITION ST_Q3_1999 VALUES LESS THAN (TO_DATE('19991001', 'YYYYMMDD')), 
  PARTITION ST_Q4_1999 VALUES LESS THAN (TO_DATE('20000101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2000 VALUES LESS THAN (TO_DATE('20000401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2000 VALUES LESS THAN (TO_DATE('20000701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2000 VALUES LESS THAN (TO_DATE('20001001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2000 VALUES LESS THAN (TO_DATE('20010101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2001 VALUES LESS THAN (TO_DATE('20010401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2001 VALUES LESS THAN (TO_DATE('20010701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2001 VALUES LESS THAN (TO_DATE('20011001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2001 VALUES LESS THAN (TO_DATE('20020101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2002 VALUES LESS THAN (TO_DATE('20020401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2002 VALUES LESS THAN (TO_DATE('20020701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2002 VALUES LESS THAN (TO_DATE('20021001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2002 VALUES LESS THAN (TO_DATE('20030101', 'YYYYMMDD')), 
  PARTITION ST_Q1_2003 VALUES LESS THAN (TO_DATE('20030401', 'YYYYMMDD')), 
  PARTITION ST_Q2_2003 VALUES LESS THAN (TO_DATE('20030701', 'YYYYMMDD')), 
  PARTITION ST_Q3_2003 VALUES LESS THAN (TO_DATE('20031001', 'YYYYMMDD')), 
  PARTITION ST_Q4_2003 VALUES LESS THAN (TO_DATE('20040101', 'YYYYMMDD')) 
)  ;


INSERT INTO SH.SALES_ORDER_PT 
SELECT PROD_ID,
       CUST_ID,
       TIME_ID - 1,
       TIME_ID,
       CHANNEL_ID,
       PROMO_ID,
       QUANTITY_SOLD,
       AMOUNT_SOLD
  FROM SH.SALES;

COMMIT;

CREATE TABLE SALES_NO_PT AS 
SELECT * FROM SH.SALES;

CREATE TABLE SALES_ORDER_NO_PT AS
SELECT PROD_ID,
       CUST_ID,
       TIME_ID - 1 AS ORDER_DT,
       TIME_ID,
       CHANNEL_ID,
       PROMO_ID,
       QUANTITY_SOLD,
       AMOUNT_SOLD
  FROM SH.SALES;