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 559<br />

6 ( partition part_1 tablespace p1,<br />

7 partition part_2 tablespace p2<br />

8 )<br />

9 /<br />

Table created.<br />

Next, we insert some data into the EMP table <strong>and</strong> then, using the partition-extended table<br />

name, inspect the contents of each partition:<br />

ops$tkyte@ORA10G> insert into emp select empno, ename from scott.emp<br />

2 /<br />

14 rows created.<br />

ops$tkyte@ORA10G> select * from emp partition(part_1);<br />

EMPNO ENAME<br />

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

7369 SMITH<br />

7499 ALLEN<br />

7654 MARTIN<br />

7698 BLAKE<br />

7782 CLARK<br />

7839 KING<br />

7876 ADAMS<br />

7934 MILLER<br />

8 rows selected.<br />

ops$tkyte@ORA10G> select * from emp partition(part_2);<br />

EMPNO ENAME<br />

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

7521 WARD<br />

7566 JONES<br />

7788 SCOTT<br />

7844 TURNER<br />

7900 JAMES<br />

7902 FORD<br />

6 rows selected.<br />

You should note that the data is somewhat r<strong>and</strong>omly assigned. That is by design here.<br />

Using hash partitioning, we are asking <strong>Oracle</strong> to r<strong>and</strong>omly—but hopefully evenly—distribute<br />

our data across many partitions. We cannot control the partition into which data goes; <strong>Oracle</strong><br />

decides that based on the hash key values that it generates. Later, when we look at range <strong>and</strong><br />

list partitioning, we’ll see how we can control what partitions receive which data.<br />

Now, we take one of the tablespaces offline (simulating, for example, a disk failure), thus<br />

making the data unavailable in that partition:<br />

ops$tkyte@ORA10G> alter tablespace p1 offline;<br />

Tablespace altered.

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

Saved successfully!

Ooh no, something went wrong!