

prompt
prompt 创建cluster shc 
declare 
    num number;
begin 
    select count(1) into num from all_clusters where cluster_name = 'SHC' and owner = 'EODA';
    if num = 1 then 
        select count(1) into num from all_tables where table_name = 'CUST_ORDERS' and owner = 'EODA';
        if num = 1 then
            execute immediate 'drop table eoda.cust_orders';
        end if;
        -- 如果还有表需要删除，在这里添加
        execute immediate 'drop cluster eoda.shc';
    end if;
    execute immediate '
        create cluster shc
        (
            cust_id    number,
            order_dt   timestamp  SORT
        )
        hashkeys 10000
        hash is cust_id 
        size 8129
    ';
end;
/

prompt 
prompt 创建eoda.cust_orders
declare 
    num number;
begin 
    select count(1) into num from all_tables where table_name = 'CUST_ORDERS' and owner = 'EODA';
    if num = 1 then
        execute immediate 'drop table eoda.cust_orders';
    end if;
    execute immediate '
        create table eoda.cust_orders 
        (
            cust_id         number,
            order_dt        timestamp SORT,
            order_number    number,
            username        varchar2(30),
            ship_addr       number,
            bill_addr       number,
            invoice_num     number
        )
        cluster shc ( cust_id, order_dt )
    ';
end;
/


prompt 
prompt 查看执行计划
set autotrace traceonly explain;
variable x number
begin 
    select 
        cust_id,order_dt,order_number
    from 
        eoda.cust_orders
    where 
        cust_id = :x
    order by order_dt;

    select 
        job,hiredate,empno 
    from 
        scott.emp 
    where job = 'CLERK' 
    order by hiredate;
end;
/
set autotrace off;
