Virtual column partitioning enables you to partition on an expression, which may use data from other columns, and perform calculations with these columns. PL/SQL function calls are not supported in virtual column definitions that are to be used as a partitioning key.
Virtual column partitioning supports all partitioning methods, plus performance and manageability features. To get partition pruning benefits, consider using virtual columns if tables are frequently accessed using a predicate that is not directly captured in a column, but can be derived. Traditionally, to get partition pruning benefits, you would have to add a separate column to capture and calculate the correct value and ensure the column is always populated correctly to ensure correct query retrieval.
Example 3-14 shows a car_rentals
table. The customer's confirmation number contains a two-character country name as the location where the rental car is picked up. Rental car analyses usually evaluate regional patterns, so it makes sense to partition by country.
In this example, the column country
is defined as a virtual column derived from the confirmation number. The virtual column does not require any storage. As the example illustrates, row movement is supported with virtual columns. The database migrates a row to a different partition if the virtual column evaluates to a different value in another partition.
Example 3-14 Creating a table with virtual columns for partitioning
CREATE TABLE car_rentals ( id NUMBER NOT NULL , customer_id NUMBER NOT NULL , confirmation_number VARCHAR2(12) NOT NULL , car_id NUMBER , car_type VARCHAR2(10) , requested_car_type VARCHAR2(10) NOT NULL , reservation_date DATE NOT NULL , start_date DATE NOT NULL , end_date DATE , country as (substr(confirmation_number,9,2)) ) PARTITION BY LIST (country) SUBPARTITION BY HASH (customer_id) SUBPARTITIONS 16 ( PARTITION north_america VALUES ('US','CA','MX') , PARTITION south_america VALUES ('BR','AR','PE') , PARTITION europe VALUES ('GB','DE','NL','BE','FR','ES','IT','CH') , PARTITION apac VALUES ('NZ','AU','IN','CN') ) ENABLE ROW MOVEMENT;