05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 13 ■ PARTITIONING 569<br />

that is less than 01-JAN-2005. However, the next insert of midnight on 01-JAN-2005 goes into<br />

partition PART_2 because that date/time is not strictly less than the partition range boundary.<br />

The last row obviously belongs in partition PART_2 since it is less than the partition range<br />

boundary for PART_2.<br />

We can confirm that this is the case by performing SELECT statements from the individual<br />

partitions:<br />

ops$tkyte@ORA10G> select to_char(range_key_column,'dd-mon-yyyy hh24:mi:ss')<br />

2 from range_example partition (part_1);<br />

TO_CHAR(RANGE_KEY_CO<br />

--------------------<br />

15-dec-2004 00:00:00<br />

31-dec-2004 23:59:59<br />

ops$tkyte@ORA10G> select to_char(range_key_column,'dd-mon-yyyy hh24:mi:ss')<br />

2 from range_example partition (part_2);<br />

TO_CHAR(RANGE_KEY_CO<br />

--------------------<br />

01-jan-2005 00:00:00<br />

15-dec-2005 00:00:00<br />

You might be wondering what would happen if you inserted a date that fell outside of the<br />

upper bound. The answer is that <strong>Oracle</strong> will raise an error:<br />

ops$tkyte@ORA10GR1> insert into range_example<br />

2 ( range_key_column, data )<br />

3 values<br />

4 ( to_date( '15/12/2007 00:00:00',<br />

5 'dd/mm/yyyy hh24:mi:ss' ),<br />

6 'application data...' );<br />

insert into range_example<br />

*<br />

ERROR at line 1:<br />

ORA-14400: inserted partition key does not map to any partition<br />

Suppose you want to segregate 2005 <strong>and</strong> 2006 dates into their separate partitions as we<br />

have, but you want all other dates to go into a third partition. With range partitioning, you can<br />

do this using the MAXVALUE clause, which looks like this:<br />

ops$tkyte@ORA10GR1> CREATE TABLE range_example<br />

2 ( range_key_column date ,<br />

3 data varchar2(20)<br />

4 )<br />

5 PARTITION BY RANGE (range_key_column)<br />

6 ( PARTITION part_1 VALUES LESS THAN<br />

7 (to_date('01/01/2005','dd/mm/yyyy')),<br />

8 PARTITION part_2 VALUES LESS THAN

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!