The following example creates a hash-partitioned table (sales) using the PARTITION BY HASH clause. The partitioning column is part_no; the number of partitions to be created is specified.
The eight partitions are created and assigned a system-generated name. The partitions are stored in the default tablespace of the table.
Example - PARTITION BY HASH...PARTITIONS num...STORE IN
The following example creates a hash-partitioned table named (sales). The number of partitions to be created and the tablespaces in which the partition will reside are specified.
The STORE IN clause evenly distributes the partitions across specified tablespaces (ts1, ts2, ts3).
Example - HASH/RANGE PARTITIONS num...
The HASH partition clause allows you to define a partitioning strategy. You can extend the PARTITION BY HASH clause to include SUBPARTITION BY either [ RANGE | LIST | HASH ] to create subpartitions in an HASH partitioned table.
The following example creates a table (sales) that is hash-partitioned by part_no and subpartitioned using range by dept_no. The number of partitions is specified when creating a table (sales).
The five partitions are created with default subpartitions and assigned system-generated names.
Example - LIST/HASH SUBPARTITIONS num...
The following example shows a table (sales) that is list-partitioned by country and subpartitioned using hash partitioning by the dept_no column. The number of subpartitions is specified when creating the table.
The three partitions p1, p2 and p3 each contain three subpartitions with system-generated names.
Example - HASH/HASH PARTITIONS num... SUBPARTITIONS num...
The following example creates the (sales) table, hash-partitioned by part_no and hash-subpartitioned by dept_no.
The two partitions are created and each partition includes three subpartitions with the system-generated name assigned to them.
Example - HASH/HASH SUBPARTITIONS num... STORE IN
The following example creates a hash-partitioned table (sales). The number of partitions and subpartitions to be created are specified along with the tablespaces in which the subpartitions will reside when creating a hash partitioned table.
The two partitions are created and assigned a system-generated name. The partitions are stored in the default tablespace and subpartitions are stored in tablespaces (ts1) and (ts2).
The STORE IN clause assigns the hash subpartitions to the tablespaces and stores them in two named tablespaces (ts1, ts2).
Example - HASH/HASH PARTITIONS num ...STORE IN SUBPARTITIONS num... STORE IN
The following example creates a hash-partitioned table (sales). The number of partitions and subpartitions to be created are specified, along with the tablespaces in which the partitions and subpartitions will reside.
The two partitions are created with a system-generated name and stored in the default tablespace.
Each partition includes three subpartitions; the STORE IN clause stores the subpartitions in tablespaces (ts1) and (ts2).
Note
If the STORE IN clause is specified for partitions and subpartitions, then the subpartitions are stored in the tablespaces defined in the PARTITIONS...STORE IN clause and the SUBPARTITIONS...STORE IN clause is ignored.
Example - RANGE/HASH SUBPARTITIONS num...
The following example creates a range-partitioned table (sales) that is first partitioned by the transaction date; two range partitions are created and then hash-subpartitioned using the value of the country column.
This statement creates a table with two partitions; the subpartition explicitly named q1_europe is created for partition p1. Because subpartitions are not named for partition p2, the subpartitions are created based on the subpartition number, and are assigned a system-generated name.
Example - RANGE/HASH SUBPARTITIONS num... IN PARTITION DESCRIPTION
The following example creates a range-partitioned table (sales) that is first partitioned by the transaction date; two range partitions are created and then hash-subpartitioned using the value of the country column.
The partition p1 explicitly defines the subpartition count in the partition description. By default, two subpartitions will be created for partition p2; since subpartitions are not named, system-generated names are assigned.
Example - LIST/HASH SUBPARTITIONS num STORE IN... IN PARTITION DESCRIPTION
The following example creates a list-partitioned table (sales) with two list partitions. Partition p1 consists of three subpartitions and partition p2 consists of two subpartitions. Since the subpartitions are not named, system-generated names are assigned.
The partition p2 explicitly defines the subpartition count in the partition description. Based on the definition, two subpartitions are created and stored in the tablespace named (ts2). The subpartitions for partition p1 will be stored in the tablespace named (ts1).
Example - LIST/HASH STORE IN...TABLESPACES
The following example creates a list-partitioned table (sales) with partition p1 consisting of three subpartitions stored explicitly in the tablespace (ts2).
The SELECT statement shows partition p1, consisting of three subpartitions stored in the tablespace (ts2).
The following command adds a new partition p2 to the sales table, five subpartitions will be created and distributed across the tablespace listed by the STORE IN clause.
A query of the ALL_TAB_PARTITIONS view shows the sales table with a partition named p2, with five subpartitions. The STORE IN clause distributes the subpartitions across a tablespace named (ts1).