variable object_number number
variable relative_fno number
variable block_number number
variable row_number number

declare
   oe_rownum    rowid;
   rowid_type   number;
begin
   select rowid into oe_rownum from oe.arch_orders
     where order_id = 2358 and rownum = 1;
   dbms_rowid.rowid_info (rowid_in => oe_rownum,
     ts_type_in => 'BIGFILE',
     rowid_type => rowid_type,
     object_number => :object_number,
     relative_fno => :relative_fno,
     block_number => :block_number,
     row_number => :row_number);
end;


create table oe.sales_summ_by_date
(    sales_date           date,
     dept_id              number,
     total_sales          number(18,2),
     constraint ssbd_pk primary key
         (sales_date, dept_id))
organization index tablespace xport_dw;


create table cat_req
    (cat_req_num       number not null,
     cat_req_dt        date not null,
     cat_cd            number not null,
     cust_num          number null,
     req_nm            varchar2(50),
     req_addr1         varchar2(75),
     req_addr2         varchar2(75),
     req_addr3         varchar2(75))
partition by range (cat_req_dt)
    (partition cat_req_spr_2007
          values less than (to_date('20070601','YYYYMMDD'))
          tablespace prd01,
     partition cat_req_sum_2007
          values less than (to_date('20070901','YYYYMMDD'))
          tablespace prd02,
     partition cat_req_fal_2007
          values less than (to_date('20071201','YYYYMMDD'))
          tablespace prd03,
     partition cat_req_win_2008
          values less than (maxvalue)
          tablespace prd04);


create table cat_req
    (cat_req_num       number not null,
     cat_req_dt        date not null,
     cat_cd            number not null,
     cust_num          number null,
     req_nm            varchar2(50),
     req_addr1         varchar2(75),
     req_addr2         varchar2(75),
     req_addr3         varchar2(75))
partition by range (cat_req_dt)
    (partition cat_req_spr_2007
          values less than (to_date('20070601','YYYYMMDD'))
          tablespace prd01,
     partition cat_req_sum_2007
          values less than (to_date('20070901','YYYYMMDD'))
          tablespace prd02,
     partition cat_req_fal_2007
          values less than (to_date('20071201','YYYYMMDD'))
          tablespace prd03,
     partition cat_req_win_2008
          values less than (maxvalue)
          tablespace prd04);


create table oe.sales_by_region_by_day
     (state_cd          char(2),
      sales_dt          date,
      sales_amt         number(16,2))
partition by list (state_cd)
   (partition midwest values ('LO','ZP','MA','WI','KP')
        tablespace prd01,
    partition westcoast values ('LU','DS','OP')
        tablespace prd02,
    partition other_states values (default)
        tablespace prd03);

create table oe.tool_rentals
  (tool_num       number,
   tool_desc      varchar2(50),
   rental_rate    number(6,2))
partition by range (tool_num)
  subpartition by hash (tool_desc)
  subpartition template (subpartition s1 tablespace prd01,
                         subpartition s2 tablespace prd02,
                         subpartition s3 tablespace prd03,
                         subpartition s4 tablespace prd04,
                         subpartition s5 tablespace prd01,
                         subpartition s6 tablespace prd02,
                         subpartition s7 tablespace prd03,
                         subpartition s8 tablespace prd04)
(partition tool_rentals_p1 values less than (101),
partition tool_rentals_p2 values less than (201),
partition tool_rentals_p3 values less than (301),
partition tool_rentals_p4 values less than (maxvalue));


select * from oe.tool_rentals partition (tool_rentals_p1);
select * from oe. tool_rentals subpartition (tool_rentals_p3_s2);


create table sales_by_region_by_quarter
     (state_cd          char(2),
      sales_dt          date,
      sales_amt         number(16,2))
partition by range (sales_dt)
     subpartition by list (state_cd)
       (partition q1_2007 values less than (to_date('20070401','YYYYMMDD'))
         (subpartition q1_2007_midwest values ('WI','IL','IA','IN','MN')
               tablespace prd01,
          subpartition q1_2007_westcoast values ('CA','OR','WA')
               tablespace prd02,
          subpartition q1_2007_other_states values (default)
               tablespace prd03
         ),
        partition q2_2007 values less than (to_date('20070701','YYYYMMDD'))
         (subpartition q2_2007_midwest values ('WI','IL','IA','IN','MN')
               tablespace prd01,
          subpartition q2_2007_westcoast values ('CA','OR','WA')
               tablespace prd02,
          subpartition q2_2007_other_states values (default)
               tablespace prd03
         ),
        partition q3_2007 values less than (to_date('20071001','YYYYMMDD'))
         (subpartition q3_2007_midwest values ('WI','IL','IA','IN','MN')
               tablespace prd01,
          subpartition q3_2007_westcoast values ('CA','OR','WA')
               tablespace prd02,
          subpartition q3_2007_other_states values (default)
               tablespace prd03
         ),
        partition q4_2007 values less than (maxvalue)
         (subpartition q4_2007_midwest values ('WI','IL','IA','IN','MN')
               tablespace prd01,
          subpartition q4_2007_westcoast values ('CA','OR','WA')
               tablespace prd02,
          subpartition q4_2007_other_states values (default)
               tablespace prd03
         )
        );


create table sales_by_region_by_quarter
     (state_cd          char(2),
      sales_dt          date,
      sales_amt         number(16,2))
partition by list (state_cd)
    subpartition by range(sales_dt)
        (partition midwest values ('WI','IL','IA','IN','MN')
          (
           subpartition midwest_q1_2007 values less than
                (to_date('20070401','YYYYMMDD')),
           subpartition midwest_q2_2007 values less than
                (to_date('20070701','YYYYMMDD')),
           subpartition midwest_q3_2007 values less than
                (to_date('20071001','YYYYMMDD')),
           subpartition midwest_q4_2007 values less than (maxvalue)
          ),
         partition westcoast values ('CA','OR','WA')
          (
           subpartition westcoast_q1_2007 values less than
                (to_date('20070401','YYYYMMDD')),
           subpartition westcoast_q2_2007 values less than
                (to_date('20070701','YYYYMMDD')),
           subpartition westcoast_q3_2007 values less than
                (to_date('20071001','YYYYMMDD')),
           subpartition westcoast_q4_2007 values less than (maxvalue)
          ),
         partition other_states values (default)
          (
           subpartition other_states_q1_2007 values less than
                (to_date('20070401','YYYYMMDD')),
           subpartition other_states_q2_2007 values less than
                (to_date('20070701','YYYYMMDD')),
           subpartition other_states_q3_2007 values less than
                (to_date('20071001','YYYYMMDD')),
           subpartition other_states_q4_2007 values less than (maxvalue)
          )
        );


create table patient_info
   (patient_id      number,
    birth_date      date,
    birth_weight_gr number)
partition by range (birth_date)
   subpartition by range (birth_weight_gr)
     (
      partition bd_1950 values less than (to_date('19501231','YYYYMMDD'))
       (
        subpartition bd_1950_4lb values less than (64),
        subpartition bd_1950_6lb values less than (96),
        subpartition bd_1950_8lb values less than (128),
        subpartition bd_1950_12lb values less than (192),
        subpartition bd_1950_o12lb values less than (maxvalue)
       ),
      partition bd_1960 values less than (to_date('19601231','YYYYMMDD'))
       (
        subpartition bd_1960_4lb values less than (64),
        subpartition bd_1960_6lb values less than (96),
        subpartition bd_1960_8lb values less than (128),
        subpartition bd_1960_12lb values less than (192),
        subpartition bd_1960_o12lb values less than (maxvalue)
       ),
partition bd_1970 values less than (to_date('19701231','YYYYMMDD'))
       (
        subpartition bd_1970_4lb values less than (64),
        subpartition bd_1970_6lb values less than (96),
        subpartition bd_1970_8lb values less than (128),
        subpartition bd_1970_12lb values less than (192),
        subpartition bd_1970_o12lb values less than (maxvalue)
       ),
      partition bd_1980 values less than (to_date('19801231','YYYYMMDD'))
       (
        subpartition bd_1980_4lb values less than (64),
        subpartition bd_1980_6lb values less than (96),
        subpartition bd_1980_8lb values less than (128),
        subpartition bd_1980_12lb values less than (192),
        subpartition bd_1980_o12lb values less than (maxvalue)
       ),
      partition bd_1990 values less than (to_date('19901231','YYYYMMDD'))
       (
        subpartition bd_1990_4lb values less than (64),
        subpartition bd_1990_6lb values less than (96),
        subpartition bd_1990_8lb values less than (128),
        subpartition bd_1990_12lb values less than (192),
        subpartition bd_1990_o12lb values less than (maxvalue)
       ),
      partition bd_2000 values less than (to_date('20001231','YYYYMMDD'))
       (
        subpartition bd_2000_4lb values less than (64),
        subpartition bd_2000_6lb values less than (96),
        subpartition bd_2000_8lb values less than (128),
        subpartition bd_2000_12lb values less than (192),
        subpartition bd_2000_o12lb values less than (maxvalue)
       ),
      partition bd_2010 values less than (maxvalue)
       (
        subpartition bd_2010_4lb values less than (64),
        subpartition bd_2010_6lb values less than (96),
        subpartition bd_2010_8lb values less than (128),
        subpartition bd_2010_12lb values less than (192),
        subpartition bd_2010_o12lb values less than (maxvalue)
       )
     );


create table order_hist_interval
  (order_num      NUMBER(15),
   cust_id        NUMBER(12),
   order_dt       date,
   order_total    NUMBER(10,2)
  )
  partition by range (order_dt)
  interval(numtoyminterval(1,'month'))
    (partition p0 values less than (to_date('20051231','YYYYMMDD')),
     partition p1 values less than (to_date('20060701','YYYYMMDD')),
     partition p2 values less than (to_date('20061231','YYYYMMDD')),
     partition p3 values less than (to_date('20070701','YYYYMMDD'))
    );


create table order_hist
  (order_num      NUMBER(15),
   cust_id        NUMBER(12),
   order_dt       date,
   order_total    NUMBER(10,2),
  constraint order_hist_pk primary key(order_num)
  )
  partition by range (order_dt)
    (partition q1_2007 values less than (to_date('20070401','YYYYMMDD')),
     partition q2_2007 values less than (to_date('20070701','YYYYMMDD')),
     partition q3_2007 values less than (to_date('20071001','YYYYMMDD')),
     partition q4_2007 values less than (to_date('20080101','YYYYMMDD'))
    )
;

create table order_item_hist
  (order_num      number(15),
   line_item_num  number(3),
   product_num    number(10),
   item_price     number(8,2),
   item_qty       number(8),
  constraint order_item_hist_fk
    foreign key (order_num) references order_hist(order_num)
  )
partition by reference(order_item_hist_fk)
;


create table order_hist_sys_part
  (order_num      NUMBER(15),
   cust_id        NUMBER(12),
   order_dt       date,
   order_total    NUMBER(10,2)
  )
  partition by system
    (partition p1 tablespace users1,
     partition p2 tablespace users2,
     partition p3 tablespace users3,
     partition p4 tablespace users4
    )
;


create table line_item_value
  (order_num      number(15) not null,
   line_item_num  number(3) not null,
   product_num    number(10),
   item_price     number(8,2),
   item_qty       number(8),
   total_price    as (item_price * item_qty)
  )
partition by range (total_price)
(
   partition small  values less than (100),
   partition medium values less than (500),
   partition large  values less than (1000),
   partition xlarge values less than (maxvalue)
);


create table cat_req_2
    (cat_req_num       number not null,
     cat_req_dt        date not null,
     cat_cd            number not null,
     cust_num          number null,
     req_nm            varchar2(50),
     req_addr1         varchar2(75),
     req_addr2         varchar2(75),
     req_addr3         varchar2(75))
partition by range (cat_req_dt)
    (partition cat_req_spr_2007
          values less than (to_date('20070601','YYYYMMDD'))
          tablespace prd01 compress,
     partition cat_req_sum_2007
          values less than (to_date('20070901','YYYYMMDD'))
          tablespace prd02 compress,
     partition cat_req_fal_2007
          values less than (to_date('20071201','YYYYMMDD'))
          tablespace prd03 nocompress,
     partition cat_req_win_2008
          values less than (maxvalue)
          tablespace prd04 nocompress);


create index cat_req_dt_ix on oe.cat_req(cat_req_dt)
 global partition by range(cat_req_dt)
 (partition spr_sum_2007
  values less than (to_date('20070901','YYYYMMDD'))
    tablespace idx_4,
 partition fal_win_2007
 values less than (maxvalue)
    tablespace idx_8);


create index oe.cust_zip_cd_ix on oe.cust(zip_cd)
 global partition by hash(zip_cd)
  (partition z1      tablespace idx_1,
   partition z2      tablespace idx_2,
   partition z3      tablespace idx_3,
   partition z4      tablespace idx_4,
   partition z5      tablespace idx_5,
   partition z6      tablespace idx_6,
   partition z7      tablespace idx_7,
   partition z8      tablespace idx_8);


create index oe.cust_ins_dt_ix on oe.cust (ins_dt)
   compress local
   store in (idx_1, idx_2, idx_3, idx_4);


CREATE TABLE "OE"."ORDER_QUOTE"
      ("ORD_QUOTE_NUM" NUMBER(12),
       "ORD_DATE" DATE,
       "CUST_NUM" NUMBER(15),
       "ORD_TYP_CD" NUMBER(1),
       "ORD_SRC_CD" NUMBER(1))
TABLESPACE "USERS" PARTITION BY RANGE ("ORD_DATE")
  (PARTITION "ORDER_QUOTE_P1"
      VALUES LESS THAN (TO_DATE('2/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P2"
      VALUES LESS THAN (TO_DATE('3/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P3"
      VALUES LESS THAN (TO_DATE('4/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P4"
      VALUES LESS THAN (TO_DATE('5/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P5"
      VALUES LESS THAN (TO_DATE('6/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P6"
      VALUES LESS THAN (TO_DATE('7/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P7"
      VALUES LESS THAN (TO_DATE('8/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P8"
      VALUES LESS THAN (TO_DATE('9/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P9"
      VALUES LESS THAN (TO_DATE('10/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P10"
      VALUES LESS THAN (TO_DATE('11/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P11"
      VALUES LESS THAN (TO_DATE('12/1/2007','MM/DD/YYYY')),
   PARTITION "ORDER_QUOTE_P12" VALUES LESS THAN (MAXVALUE));


