test hash
create table test_acc_app1_top20
(
App1_Seq NUMBER not null,
Card_Logical_Number varchar2(20), --卡邏輯號
Data_DateTime date, --时间
Tran_Money number(10,1), --扣值或充值額
App_Times number --錢包累計交易次數(新福利舊卡寫入0000)
)
partition by hash(Card_Logical_Number)
(
partition PD1801 TABLESPACE PD1801,
partition PD1802 TABLESPACE PD1802,
partition PD1803 TABLESPACE PD1803
);
alter table test_acc_app1_top20
add constraint pk_test_acc_app1_top20 primary key (Card_Logical_Number,App1_Seq)
using index local
(
PARTITION PD1801 TABLESPACE I_PD1801,
PARTITION PD1802 TABLESPACE I_PD1802,
PARTITION PD1803 TABLESPACE I_PD1803
);
create index idx_test_acc_app1_top20 on test_acc_app1_top20 (Card_Logical_Number,Data_DateTime desc)
local
(
PARTITION PD1801 TABLESPACE I_PD1801,
PARTITION PD1802 TABLESPACE I_PD1802,
PARTITION PD1803 TABLESPACE I_PD1803
);
SELECT a.*,TABLE_NAME, A.INDEX_NAME, A.TABLESPACE_NAME
FROM USER_IND_PARTITIONS A, USER_INDEXES B
WHERE A.INDEX_NAME = B.INDEX_NAME
and A.INDEX_NAME=upper('pk_test_acc_app1_top20')
ORDER BY 1, 2;
SELECT a.*,TABLE_NAME, A.INDEX_NAME, A.TABLESPACE_NAME
FROM USER_IND_PARTITIONS A, USER_INDEXES B
WHERE A.INDEX_NAME = B.INDEX_NAME
and A.INDEX_NAME=upper('idx_test_acc_app1_top20')
ORDER BY 1, 2;
insert into test_acc_app1_top20
select a.app1_seq,a.card_logical_number,a.transact_time,a.mid_transact_value,a.app1_times from acc_app1 a
select * from test_acc_app1_top20 partition(PD1802)
where card_logical_number='FFD01157'
-----------------------------------------------------
drop table test_acc_app1_top20
create table test_acc_app1_top20
(
App1_Seq NUMBER not null,
Card_Logical_Number varchar2(20), --卡邏輯號
Data_DateTime date --时间
)
partition by hash(Card_Logical_Number)
(
partition PD1801 TABLESPACE PD1801,
partition PD1802 TABLESPACE PD1802
);
alter table test_acc_app1_top20
add constraint pk_test_acc_app1_top20 primary key (Card_Logical_Number,App1_Seq)
using index local
(
PARTITION PD1801 TABLESPACE I_PD1801,
PARTITION PD1802 TABLESPACE I_PD1802
);
create index idx_test_acc_app1_top20 on test_acc_app1_top20 (Card_Logical_Number,Data_DateTime desc)
local
(
PARTITION PD1801 TABLESPACE I_PD1801,
PARTITION PD1802 TABLESPACE I_PD1802
);
---------
create table test_acc_app1_top20
(
App1_Seq NUMBER not null,
Card_Logical_Number varchar2(20), --卡邏輯號
Data_DateTime date --时间
)
partition by hash(Card_Logical_Number)
(
partition PD1801 TABLESPACE PD1801,
partition PD1802 TABLESPACE PD1802,
partition PD1803 TABLESPACE PD1803,
partition PD1804 TABLESPACE PD1804
);
alter table test_acc_app1_top20
add constraint pk_test_acc_app1_top20 primary key (Card_Logical_Number,App1_Seq)
using index local
(
PARTITION PD1801 TABLESPACE I_PD1801,
PARTITION PD1802 TABLESPACE I_PD1802,
PARTITION PD1803 TABLESPACE I_PD1803,
PARTITION PD1804 TABLESPACE I_PD1804
);
create index idx_test_acc_app1_top20 on test_acc_app1_top20 (Card_Logical_Number,Data_DateTime desc)
local
(
PARTITION PD1801 TABLESPACE I_PD1801,
PARTITION PD1802 TABLESPACE I_PD1802,
PARTITION PD1803 TABLESPACE I_PD1803,
PARTITION PD1804 TABLESPACE I_PD1804
);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(1,'F1',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(2,'F2',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(4,'F4',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(3,'F3',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(6,'F6',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(5,'F5',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(7,'F7',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(8,'F8',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(9,'F9',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(11,'F1',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(12,'F2',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(13,'F3',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(21,'F10',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(22,'F11',sysdate);
insert into test_acc_app1_top20(app1_seq,card_logical_number,data_datetime)
values(23,'F12',sysdate);
---------
/*
alter table test_acc_app1_top20
add PARTITION PD1803 TABLESPACE PD1803;
alter table test_acc_app1_top20
add PARTITION PD1804 TABLESPACE PD1804;
alter index PK_TEST_ACC_APP1_TOP20 rebuild partition PD1803 TABLESPACE I_PD1803;
alter index PK_TEST_ACC_APP1_TOP20 rebuild partition PD1804 TABLESPACE I_PD1804;
alter index pk_test_acc_app1_top20 rebuild partition PD1803 TABLESPACE I_PD1803 ;
alter index idx_test_acc_app1_top20 rebuild partition PD1803 TABLESPACE I_PD1803 ;
*/
select * from test_acc_app1_top20 partition(PD1801) a;
select * from test_acc_app1_top20 partition(PD1802) a;
select * from test_acc_app1_top20 partition(PD1803) a;
select * from test_acc_app1_top20 partition(PD1804) a;
select ora_hash(card_logical_number,3)+1 as a,t.* from test_acc_app1_top20 t
select card_logical_number,count(1) from test_acc_app1_top20
group by card_logical_number