053-224

224.You need to create a partitioned table to store historical data and you issued the following command:
CREATE TABLE purchase_interval PARTITION BY RANGE (time_id) INTERVAL
(NUMTOYMINTERVAL(1,'month')) STORE IN (tbs1,tbs2,tbs3) ( PARTITION p1 VALUES LESS
THAN(TO_DATE('1-1-2005', 'dd-mm-yyyy')), PARTITION p2 VALUES LESS THAN(TO_DATE('1-1- 2007',
'dd-mm-yyyy'))) AS SELECT * FROM purchases WHERE time_id < TO_DATE('1-1-2007','dd-mm-yyyy');
What is the outcome of the above command?
A. It returns an error because the range partitions P1 and P2 should be of the same range.
B. It creates two range partitions (P1, P2). Within each range partition, it creates monthwise subpartitions.
C. It creates two range partitions of varying range. For data beyond '1-1-2007,' it creates partitions with a
width of one month each.
D. It returns an error because the number of tablespaces (TBS1,TBS2,TBS3)specified does not match
the number of range partitions (P1,P2) specified.
Answer: C

解析:
NUMTOYMINTERVAL converts number n to an INTERVAL YEAR TO MONTH literal. The argument n can be any NUMBER value or an expression that can be implicitly converted to a NUMBER value. The argument interval_unit can be of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype. The value for interval_unit specifies the unit of n and must resolve to one of the following string values:
'YEAR'
'MONTH'

create tablespace tbs1 datafile '/oradata/tbs1.dbf' size 50M;
create tablespace tbs2 datafile '/oradata/tbs2.dbf' size 50M;
create tablespace tbs3 datafile '/oradata/tbs3.dbf' size 50M;

create table employee  (id int,name varchar2(10),hire_date date);
insert into employee values (1,'a',to_date('20120103','yyyymmdd'));
insert into employee values (2,'b',to_date('20120204','yyyymmdd'));
insert into employee values (3,'c',to_date('20120303','yyyymmdd'));
insert into employee values (4,'d',to_date('20120403','yyyymmdd'));
insert into employee values (5,'e',to_date('20120503','yyyymmdd'));
insert into employee values (6,'f',to_date('20120603','yyyymmdd'));
insert into employee values (7,'g',to_date('20120703','yyyymmdd'));
insert into employee values (10,'g',to_date('20121003','yyyymmdd'));
insert into employee values (10,'g',to_date('20121103','yyyymmdd'));
insert into employee values (11,'g',to_date('20121203','yyyymmdd'));
commit;
CREATE TABLE emp PARTITION BY range(hire_date) INTERVAL
(NUMTOYMINTERVAL(1,'month')) store in  (tbs1,tbs2,tbs3)  ( PARTITION p1 VALUES LESS
THAN(TO_DATE('1-3-2012', 'dd-mm-yyyy')), PARTITION p2 VALUES LESS THAN(TO_DATE('1-5- 2012',
'dd-mm-yyyy'))) AS SELECT * FROM employee WHERE hire_date < TO_DATE('1-1-2014','dd-mm-yyyy');

select * from dba_segments a where owner='LBX' and a.segment_name='EMP';

圖1:

ocp_224

圖2:

ocp_224_2

經過實驗,答案選C是沒問題.

參數 store in  (tbs1,tbs2,tbs3) 怎麼起作用的,看的還是有點迷糊!P1和P2分區竟然放在默認分區TBS_TPSS_DATA.別的系統自動生成的分區隨機分佈在tbs1-3裏面.

事實上,oracle網站是這麼描述的:

hash_partitions_by_quantity:

Alternatively, you can specify the number of partitions. In this case, the database assigns partition names of the form SYS_Pn. The STORE IN clause specifies one or more tablespaces where the hash partitions are to be stored. The number of tablespaces does not have to equal the number of partitions. If the number of partitions is greater than the number of tablespaces, then the database cycles through the names of the tablespaces.

參考:

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7002.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章