What is List-Hash Partitioning in Oracle

List-Hash Partitioning in Oracle is a type of composite partitioning that combines List Partitioning and Hash Partitioning.

In this method:

  1. First, Oracle divides the table into partitions based on specific values using List Partitioning.
  2. Then, each main partition is further divided into smaller subpartitions using a hashing algorithm.
It is useful when we want to organize data based on categories and distribute records within each category.

1. Real-time Example

Suppose we are working on an employee management application.

We have an EMPLOYEES table containing 10 lakh records.

We want to divide the data using two conditions:

  • First level: Divide employee records department-wise using DEPARTMENT.
  • Second level: Distribute each department's records using Hash Partitioning based on EMP_ID.

Example: Partition Structure

Main Partition Subpartitions
P_IT 4 Hash Subpartitions
P_HR 4 Hash Subpartitions
P_FINANCE 4 Hash Subpartitions
Remember:
  • List Partitioning separates employees department-wise.
  • Hash Partitioning distributes employees within each department.

Reference: Oracle Partitioning in Oracle Database – Presentation

2. SQL Example

Let's create a List-Hash partitioned table in Oracle.

CREATE TABLE employees
(
    emp_id NUMBER,
    emp_name VARCHAR2(100),
    department VARCHAR2(30),
    salary NUMBER
)
PARTITION BY LIST (department)
SUBPARTITION BY HASH (emp_id)
SUBPARTITIONS 4
(
    PARTITION p_it VALUES ('IT'),

    PARTITION p_hr VALUES ('HR'),

    PARTITION p_finance VALUES ('FINANCE')
);

3. Explanation of the SQL Query

  • PARTITION BY LIST (department) divides employees based on department values.
  • SUBPARTITION BY HASH (emp_id) further divides each department partition using Employee ID.
  • SUBPARTITIONS 4 creates four hash subpartitions inside each main partition.
  • Oracle automatically distributes records into the appropriate hash subpartitions.

Total Number of Subpartitions

3 Main Partitions × 4 Subpartitions = 12 Subpartitions

4. Insert Sample Records

Let's insert some sample records into the employees table.

INSERT INTO employees
VALUES (101, 'Ravi', 'IT', 50000);

INSERT INTO employees
VALUES (102, 'Kumar', 'HR', 40000);

INSERT INTO employees
VALUES (103, 'Raj', 'FINANCE', 60000);

INSERT INTO employees
VALUES (104, 'Suresh', 'IT', 45000);

COMMIT;

What Happens Internally?

For each inserted record:

  1. Oracle checks the department value.
  2. It identifies the appropriate main partition.
  3. Oracle applies the hashing algorithm to EMP_ID.
  4. It stores the record in the appropriate hash subpartition.

Where Will the Records Be Stored?

Employee ID Department Main Partition
101 IT P_IT
102 HR P_HR
103 FINANCE P_FINANCE
104 IT P_IT

Each employee is further assigned to one of the four hash subpartitions within that department.

Important: Oracle determines the actual hash subpartition using its internal hashing algorithm. We should not assume a particular Employee ID will always belong to a specific numbered subpartition.

5. How to Check Partitions and Subpartitions?

To Check Main Partitions

SELECT
    TABLE_NAME,
    PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'EMPLOYEES';

To Check Subpartitions

SELECT
    TABLE_NAME,
    PARTITION_NAME,
    SUBPARTITION_NAME
FROM USER_TAB_SUBPARTITIONS
WHERE TABLE_NAME = 'EMPLOYEES';
Note: USER_TAB_PARTITIONS and USER_TAB_SUBPARTITIONS display partition information for tables owned by the current user.

6. Advantages of List-Hash Partitioning

  1. Organizes data based on specific categories.
  2. Distributes records across multiple subpartitions.
  3. Helps manage large tables efficiently.
  4. Supports partition and subpartition pruning.
  5. Combines the benefits of List and Hash Partitioning.

7. Interview-Ready Answer

Question: What is List-Hash Partitioning in Oracle?

Answer:

"List-Hash Partitioning in Oracle is a composite partitioning technique that combines List Partitioning and Hash Partitioning. First, data is divided into partitions based on specific values, such as department names (IT, HR, and Finance). Then each partition is further divided into subpartitions using a hashing algorithm based on Employee ID. It helps organize large volumes of data and distribute records efficiently."

8. Difference Between Range-Hash, Range-List, and List-Hash

Type First-Level Partition Second-Level Subpartition
Range-Hash Range Hash
Range-List Range List
List-Hash List Hash
Interview Tip: Remember These Three Types
  • Range-Hash: Year-wise + Hash distribution.
  • Range-List: Year-wise + Category-wise.
  • List-Hash: Department-wise + Hash distribution.

9. Important Point to Remember

The first partitioning method determines the main partition, and the second partitioning method determines how that partition is further divided.

In List-Hash Partitioning:

  • List Partitioning determines the department.
  • Hash Partitioning determines the subpartition within that department.

Conclusion

List-Hash Partitioning is useful when we need to divide large Oracle tables based on specific categories and distribute records within those categories.

List Partitioning handles category-wise separation, while Hash Partitioning distributes records across multiple subpartitions.

Understanding this concept is important for Oracle Database Developers and DBAs, especially when working with large tables.

What is Range-List Partitioning in Oracle

Range-List Partitioning in Oracle is a type of composite partitioning that combines Range Partitioning and List Partitioning.

In this method:
  1. First, Oracle divides a table into partitions based on a range of values.
  2. Then, each main partition is further divided into subpartitions based on specific values.
It is useful when we want to organize large amounts of data using two different conditions.

1. Real-time Example

Suppose we are working on a banking application.

We have a TRANSACTIONS table containing 10 crore records.

We want to divide the data using two conditions:

  • First level: Divide transaction records year-wise using TRANSACTION_DATE.
  • Second level: Divide each year's data department-wise using DEPARTMENT.

Example: Partition Structure

Main Partition Subpartitions
P2024 IT, HR, FINANCE
P2025 IT, HR, FINANCE
P2026 IT, HR, FINANCE
Remember:
  • Range Partitioning separates records year-wise.
  • List Partitioning separates records department-wise within each year.

Reference: Partitioning Basics – PowerPoint Presentation

2. SQL Example

Let's create a Range-List partitioned table in Oracle.

CREATE TABLE transactions
(
    transaction_id NUMBER,
    customer_id NUMBER,
    transaction_date DATE,
    department VARCHAR2(30),
    amount NUMBER
)
PARTITION BY RANGE (transaction_date)
SUBPARTITION BY LIST (department)
(
    PARTITION p2024 VALUES LESS THAN
    (DATE '2025-01-01')
    (
        SUBPARTITION p2024_it
        VALUES ('IT'),

        SUBPARTITION p2024_hr
        VALUES ('HR'),

        SUBPARTITION p2024_finance
        VALUES ('FINANCE')
    ),

    PARTITION p2025 VALUES LESS THAN
    (DATE '2026-01-01')
    (
        SUBPARTITION p2025_it
        VALUES ('IT'),

        SUBPARTITION p2025_hr
        VALUES ('HR'),

        SUBPARTITION p2025_finance
        VALUES ('FINANCE')
    )
);

3. Explanation of the SQL Query

  • PARTITION BY RANGE (transaction_date) divides the table based on transaction dates.
  • SUBPARTITION BY LIST (department) further divides each partition based on department values.
  • p2024 stores records before 01-Jan-2025.
  • p2025 stores records from 01-Jan-2025 to before 01-Jan-2026 that are not in the previous partition.
  • Each year is divided into IT, HR, and Finance subpartitions.

Total Number of Subpartitions

2 Main Partitions × 3 Subpartitions = 6 Subpartitions

4. Insert Sample Records

Let's insert some sample records into the transactions table.

INSERT INTO transactions
VALUES (101, 1001, DATE '2024-05-10',
        'IT', 5000);

INSERT INTO transactions
VALUES (102, 1002, DATE '2025-06-15',
        'HR', 7000);

INSERT INTO transactions
VALUES (103, 1003, DATE '2025-03-20',
        'FINANCE', 9000);

COMMIT;

What Happens Internally?

For each inserted record:

  1. Oracle checks the TRANSACTION_DATE.
  2. It identifies the appropriate year partition.
  3. Oracle checks the DEPARTMENT value.
  4. It stores the record in the corresponding list subpartition.

Where Will the Records Be Stored?

Transaction ID Date Department Stored In
101 10-May-2024 IT P2024_IT
102 15-Jun-2025 HR P2025_HR
103 20-Mar-2025 FINANCE P2025_FINANCE

5. How to Check Partitions and Subpartitions?

To Check Main Partitions

SELECT TABLE_NAME, PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'TRANSACTIONS';

To Check Subpartitions

SELECT
    TABLE_NAME,
    PARTITION_NAME,
    SUBPARTITION_NAME
FROM USER_TAB_SUBPARTITIONS
WHERE TABLE_NAME = 'TRANSACTIONS';
Note: Oracle stores partition information in data dictionary views. The above USER views show information for objects owned by the current user.

6. Advantages of Range-List Partitioning

  1. Organizes large data based on two different conditions.
  2. Makes data management easier.
  3. Supports partition and subpartition pruning.
  4. Helps retrieve specific categories of data efficiently.
  5. Simplifies maintenance of large tables.

7. Interview-Ready Answer

Question: What is Range-List Partitioning in Oracle?

Answer:

"Range-List Partitioning in Oracle is a composite partitioning technique that combines Range Partitioning and List Partitioning. First, data is divided into partitions based on a range of values, such as transaction dates. Then each partition is further divided into subpartitions based on specific values, such as department names (IT, HR, and Finance). It helps organize large volumes of data and improves query performance through partition pruning."

8. Difference Between Range-Hash and Range-List Partitioning

Range-Hash Range-List
First level uses Range. First level uses Range.
Second level uses Hash. Second level uses List.
Data is distributed using a hashing algorithm. Data is divided using specific values.
Example: Year-wise + Customer ID. Example: Year-wise + Department.
Interview Tip: Remember the Difference
  • Range-Hash: Year-wise + Hash-based distribution.
  • Range-List: Year-wise + Category-wise distribution.

9. Important Note

In this example, the department column is illustrative. In a real banking application, you might use a business category, region, or transaction type instead.

Also, the example explicitly defines two yearly partitions. To accommodate 2026 and future dates, additional partitions or an appropriate partition maintenance strategy should be implemented. Rows with department values outside IT, HR, and FINANCE will not match these explicitly defined list subpartitions.

Conclusion

Range-List Partitioning is useful when we need to divide large Oracle tables using two different conditions. Range Partitioning handles date-wise or numerical ranges, while List Partitioning divides the data into specific categories.

Understanding this concept is important for Oracle Database Developers and DBAs, especially when working with large tables.

What is range-hash partitioning

Range-Hash Partitioning in Oracle is a type of composite partitioning that combines Range Partitioning and Hash Partitioning to divide large tables into smaller partitions and subpartitions.

In simple words, Oracle first divides the table into partitions based on a range of values. Then, it further divides each partition into smaller subpartitions using a hashing algorithm.

It is useful for managing large tables containing millions or billions of records.

1. What is Range-Hash Partitioning in Oracle?

Range-Hash Partitioning in Oracle is a composite partitioning technique that combines two partitioning methods.

In this method:

  1. First, Oracle divides the table into partitions based on a range of values using Range Partitioning.
  2. Then, Oracle further divides each partition into smaller subpartitions using a hashing algorithm through Hash Partitioning.
Simple Example:

First, divide transaction records year-wise using Range Partitioning. Then distribute each year's records into four subpartitions using Hash Partitioning based on CUSTOMER_ID.

2. Real-time Example

Suppose we are working on a banking application.

We have a TRANSACTIONS table containing 10 crore records.

We want to divide the data using two conditions:

  • First level: Divide transaction records year-wise using TRANSACTION_DATE.
  • Second level: Distribute each year's records using CUSTOMER_ID with Hash Partitioning.

Example partition structure:

Main Partition Subpartitions
P2024 4 Hash Subpartitions
P2025 4 Hash Subpartitions
P2026 4 Hash Subpartitions

Here:

  • Range Partitioning separates records year-wise.
  • Hash Partitioning distributes records within each year.

3. SQL Example – Create Range-Hash Partitioned Table

Let's create a Range-Hash partitioned table in Oracle.

CREATE TABLE transactions
(
    transaction_id NUMBER,
    customer_id NUMBER,
    transaction_date DATE,
    amount NUMBER
)
PARTITION BY RANGE (transaction_date)
SUBPARTITION BY HASH (customer_id)
SUBPARTITIONS 4
(
    PARTITION p2024 VALUES LESS THAN
    (DATE '2025-01-01'),

    PARTITION p2025 VALUES LESS THAN
    (DATE '2026-01-01'),

    PARTITION p2026 VALUES LESS THAN
    (DATE '2027-01-01')
);

4. Explanation of the SQL Query

  • PARTITION BY RANGE (transaction_date) divides the table based on transaction dates.
  • SUBPARTITION BY HASH (customer_id) further divides each main partition using CUSTOMER_ID.
  • SUBPARTITIONS 4 creates four hash subpartitions inside each main partition.
  • Oracle automatically distributes records across the appropriate subpartitions.
Total Subpartitions Calculation:

3 main partitions × 4 subpartitions = 12 subpartitions.

Each main partition contains four hash subpartitions.
Important: Range Partitioning is the main partitioning method, and Hash Partitioning is the subpartitioning method. Oracle first identifies the main partition based on TRANSACTION_DATE and then identifies the subpartition based on CUSTOMER_ID.

5. Insert Sample Records

Let's insert some sample transaction records into the TRANSACTIONS table.

INSERT INTO transactions
VALUES (101, 1001, DATE '2024-05-10', 5000);

INSERT INTO transactions
VALUES (102, 1002, DATE '2025-06-15', 7000);

INSERT INTO transactions
VALUES (103, 1003, DATE '2026-03-20', 9000);

COMMIT;

What happens internally?

For each inserted record:

  1. Oracle checks the TRANSACTION_DATE.
  2. It identifies the appropriate year partition.
  3. Oracle applies the hashing algorithm to CUSTOMER_ID.
  4. It stores the record in the appropriate hash subpartition.
Example:

If a transaction has a date of 15-Jun-2025, Oracle first selects the P2025 main partition. Then it uses the CUSTOMER_ID hash value to determine the appropriate subpartition within P2025.

6. How to Check Partitions and Subpartitions?

To check the main partitions available in the TRANSACTIONS table:

SELECT
    TABLE_NAME,
    PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'TRANSACTIONS'
ORDER BY PARTITION_POSITION;

To check the subpartitions:

SELECT
    TABLE_NAME,
    PARTITION_NAME,
    SUBPARTITION_NAME
FROM USER_TAB_SUBPARTITIONS
WHERE TABLE_NAME = 'TRANSACTIONS'
ORDER BY PARTITION_NAME, SUBPARTITION_POSITION;

These queries display the main partitions and their corresponding hash subpartitions.

Interview Tip:
USER_TAB_PARTITIONS displays main partition information, whereas USER_TAB_SUBPARTITIONS displays subpartition information.

7. Advantages of Range-Hash Partitioning

  1. Efficiently manages large volumes of data.
  2. Distributes data across multiple subpartitions.
  3. Supports partition pruning and subpartition pruning when queries filter on the relevant partitioning columns.
  4. Makes data maintenance easier.
  5. Combines the benefits of Range and Hash Partitioning.
  6. Provides better data organization for large database tables.

8. Interview-Ready Answer

Question: What is Range-Hash Partitioning in Oracle?

Answer:

Range-Hash Partitioning in Oracle is a composite partitioning technique that combines Range Partitioning and Hash Partitioning. First, data is divided into partitions based on a range of values, such as transaction dates. Then each partition is further divided into subpartitions using a hashing algorithm, such as CUSTOMER_ID. It helps manage large tables and improves data organization and query performance.

9. Difference Between Range-Hash and Range-List Partitioning

One of the important Oracle interview questions is the difference between Range-Hash Partitioning and Range-List Partitioning.

Range-Hash Partitioning Range-List Partitioning
First level uses Range. First level uses Range.
Second level uses Hash. Second level uses List.
Distributes data using hashing. Divides data using specific values.
Example: Year-wise + Customer ID. Example: Year-wise + Department.

10. Important Interview Point

Remember this simple formula:

Range-Hash = Range Partitioning + Hash Subpartitioning

Range: Year-wise division.

Hash: Distributes customer records within each year using a hashing algorithm.

This is a commonly discussed example in Oracle DBA and SQL Developer interviews.

Conclusion

Range-Hash Partitioning is an important Oracle Database feature used to manage very large tables efficiently. It combines Range Partitioning and Hash Partitioning to provide better data organization and flexibility.

Understanding Range-Hash Partitioning, its SQL syntax, partition and subpartition concepts, and practical implementation is important for Oracle SQL and PL/SQL developer interviews.

ORACLE SQL | RANGE-HASH PARTITIONING | COMPOSITE PARTITIONING | ORACLE DBA | ORACLE INTERVIEW QUESTIONS

What is composite partitioning

Composite Partitioning in Oracle is a partitioning technique that combines two partitioning methods to divide a large table into smaller partitions and subpartitions.

In simple words, we first divide the table using one partitioning method, and then divide each partition further using another partitioning method.

It is useful when a table contains millions or billions of records and we need more flexible data management.

1. Real-time Example

Suppose we are working on a banking application.

We have a TRANSACTIONS table containing 10 crore records.

We want to divide the data using two conditions:

  • First level: Divide data year-wise using Range Partitioning.
  • Second level: Divide each year's data using Hash Partitioning based on CUSTOMER_ID.
Real-time scenario:
Consider a banking application where millions of transactions are generated every year. We can first divide transaction records year-wise using Range Partitioning and then distribute each year's records into four subpartitions using Hash Partitioning based on CUSTOMER_ID.

Example partition structure:

Main Partition Subpartitions
P2024 P2024_SP1, P2024_SP2, P2024_SP3, P2024_SP4
P2025 P2025_SP1, P2025_SP2, P2025_SP3, P2025_SP4
P2026 P2026_SP1, P2026_SP2, P2026_SP3, P2026_SP4

Here:

  • Range Partitioning divides records year-wise.
  • Hash Subpartitioning distributes records based on CUSTOMER_ID.

2. SQL Example – Create Composite Partitioned Table

Let's create a composite-partitioned table using Range Partitioning and Hash Subpartitioning.

CREATE TABLE transactions
(
    transaction_id NUMBER,
    customer_id NUMBER,
    transaction_date DATE,
    amount NUMBER
)
PARTITION BY RANGE (transaction_date)
SUBPARTITION BY HASH (customer_id)
SUBPARTITIONS 4
(
    PARTITION p2024 VALUES LESS THAN
    (DATE '2025-01-01'),

    PARTITION p2025 VALUES LESS THAN
    (DATE '2026-01-01'),

    PARTITION p2026 VALUES LESS THAN
    (DATE '2027-01-01')
);

3. Explanation of the SQL Query

  • PARTITION BY RANGE (transaction_date) divides the table year-wise based on transaction_date.
  • SUBPARTITION BY HASH (customer_id) further divides each partition using customer_id.
  • SUBPARTITIONS 4 creates four subpartitions inside each main partition.
  • Oracle automatically distributes records into the appropriate subpartitions.
Total Subpartitions Calculation:

3 main partitions × 4 subpartitions = 12 subpartitions.

Each main partition contains four subpartitions.
Important: In this example, Range Partitioning is the main partitioning method and Hash Partitioning is the subpartitioning method. Oracle first identifies the main partition based on transaction_date and then identifies the subpartition based on customer_id.

4. Insert Sample Records

Let's insert some sample transaction records into the transactions table.

INSERT INTO transactions
VALUES (101, 1001, DATE '2024-05-10', 5000);

INSERT INTO transactions
VALUES (102, 1002, DATE '2025-06-15', 7000);

INSERT INTO transactions
VALUES (103, 1003, DATE '2026-03-20', 9000);

COMMIT;

What happens internally?

  1. Oracle identifies the year based on transaction_date.
  2. Oracle selects the appropriate main partition.
  3. Oracle applies the hash algorithm on customer_id.
  4. Oracle stores the record in the appropriate subpartition.
Example:

If a transaction has a date of 15-Jun-2025, Oracle first selects the P2025 main partition. Then it uses the CUSTOMER_ID hash value to determine the appropriate subpartition within P2025.

5. How to Check Partitions and Subpartitions?

To check the main partitions available in the transactions table:

SELECT
    TABLE_NAME,
    PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'TRANSACTIONS'
ORDER BY PARTITION_POSITION;

To check the subpartitions:

SELECT
    TABLE_NAME,
    PARTITION_NAME,
    SUBPARTITION_NAME
FROM USER_TAB_SUBPARTITIONS
WHERE TABLE_NAME = 'TRANSACTIONS'
ORDER BY PARTITION_NAME, SUBPARTITION_POSITION;

These queries display the main partitions and their corresponding subpartitions.

Interview Tip:
USER_TAB_PARTITIONS displays main partition information, whereas USER_TAB_SUBPARTITIONS displays subpartition information.

6. Advantages of Composite Partitioning

  1. Handles very large volumes of data efficiently.
  2. Provides better data organization.
  3. Supports partition pruning at partition and subpartition levels.
  4. Improves data management and maintenance.
  5. Combines the benefits of two partitioning methods.
  6. Provides flexibility when designing large database tables.

7. Interview-Ready Answer

Question: What is Composite Partitioning in Oracle?

Answer:

Composite Partitioning in Oracle is a technique that combines two partitioning methods. First, data is divided into main partitions using one method, and then each partition is further divided into subpartitions using another method. For example, we can divide a banking transaction table year-wise using Range Partitioning and further distribute each year's data using Hash Partitioning based on CUSTOMER_ID. It helps manage large volumes of data efficiently.

8. Difference Between All Oracle Partitioning Types

One of the important Oracle interview questions is the difference between the different types of partitioning.

Partitioning Type How Data Is Divided Example
Range Based on a range of values. Year-wise
List Based on specific values. Department-wise
Hash Using a hashing algorithm. Employee ID
Interval Automatically creates new range partitions. Monthly data
Reference Based on parent-child relationship. Orders and Order_Items
Composite Combination of two partitioning methods. Range + Hash

9. Important Interview Tip

Remember this simple example:

Range + Hash = Composite Partitioning

Range: Year-wise division.

Hash: Customer-wise distribution within each year.

This is a commonly discussed example in Oracle DBA and SQL developer interviews.

Conclusion

Composite Partitioning is an important Oracle Database feature used to manage very large tables efficiently. It combines two partitioning methods to provide better data organization and flexibility.

Understanding Composite Partitioning, its SQL syntax, partition and subpartition concepts, and practical implementation is important for Oracle SQL and PL/SQL developer interviews.

ORACLE SQL | COMPOSITE PARTITIONING | DATABASE PARTITIONING | ORACLE INTERVIEW QUESTIONS

What is Reference Partitioning in Oracle

Reference Partitioning in Oracle is a partitioning technique in which a child table inherits the partitioning structure of its parent table through a foreign key relationship.

In simple words, when we insert records into a child table, Oracle automatically places those records into the corresponding partition based on the related parent table record.

It is useful when two tables are related through a primary key and foreign key relationship.

1. Real-time Example

Suppose we are working on a banking or e-commerce application.

We have two tables:

  • ORDERS: Parent table that stores order details.
  • ORDER_ITEMS: Child table that stores individual items belonging to each order.
Real-time scenario:
Consider an e-commerce application where millions of orders are stored in the ORDERS table. Each order can contain multiple items stored in the ORDER_ITEMS table.

We partition the ORDERS table based on ORDER_DATE. Using Reference Partitioning, the ORDER_ITEMS table automatically follows the partitioning structure of the ORDERS table.
Parent-Child Relationship:

ORDERS (Parent Table)
↓
ORDER_ITEMS (Child Table)

The ORDER_ITEMS table follows the partitioning structure of the ORDERS table through the foreign key relationship.

2. SQL Example – Create Parent Table

Step 1: First, create the parent table named ORDERS and partition it based on ORDER_DATE.

CREATE TABLE orders
(
    order_id NUMBER PRIMARY KEY,
    order_date DATE,
    customer_name VARCHAR2(100)
)
PARTITION BY RANGE (order_date)
(
    PARTITION p2024 VALUES LESS THAN
    (DATE '2025-01-01'),

    PARTITION p2025 VALUES LESS THAN
    (DATE '2026-01-01'),

    PARTITION p2026 VALUES LESS THAN
    (DATE '2027-01-01')
);

Here, the ORDERS table is partitioned based on the ORDER_DATE column.

Explanation:

  • PARTITION BY RANGE (order_date) specifies the partitioning column.
  • p2024 stores orders before 01-Jan-2025.
  • p2025 stores orders from 01-Jan-2025 to before 01-Jan-2026.
  • p2026 stores orders from 01-Jan-2026 to before 01-Jan-2027.

3. SQL Example – Create Child Table Using Reference Partitioning

Step 2: Now create the child table ORDER_ITEMS using Reference Partitioning.

CREATE TABLE order_items
(
    item_id NUMBER,
    order_id NUMBER,
    product_name VARCHAR2(100),
    quantity NUMBER,

    CONSTRAINT fk_order
    FOREIGN KEY (order_id)
    REFERENCES orders(order_id)
)
PARTITION BY REFERENCE (fk_order);

Explanation:

  • order_items is the child table.
  • orders is the parent table.
  • fk_order is the foreign key constraint.
  • PARTITION BY REFERENCE (fk_order) tells Oracle to inherit the parent table's partitioning structure.
Important: Reference Partitioning requires a suitable foreign key relationship between the parent and child tables. The foreign key must reference an appropriate primary key or unique key in the parent table.

4. Insert Sample Records

First, insert records into the parent table ORDERS.

INSERT INTO orders
VALUES (101, DATE '2025-05-10', 'Ravi');

INSERT INTO orders
VALUES (102, DATE '2026-03-15', 'Kumar');

COMMIT;

Now insert records into the child table ORDER_ITEMS.

INSERT INTO order_items
VALUES (1, 101, 'Laptop', 1);

INSERT INTO order_items
VALUES (2, 102, 'Mobile', 2);

COMMIT;

What happens internally?

Oracle automatically stores the child records in the corresponding partitions based on their parent records.

Order ID Parent Partition Child Partition
101 P2025 Corresponding P2025
102 P2026 Corresponding P2026
Important Point:
We do not need to define separate partitioning rules for the ORDER_ITEMS table. Oracle automatically maintains the parent-child partition relationship through Reference Partitioning.

5. How to Check Partitions?

To check the parent table partitions, execute the following query:

SELECT
    TABLE_NAME,
    PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'ORDERS';

To check the child table partitions:

SELECT
    TABLE_NAME,
    PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'ORDER_ITEMS';

These queries display the partition names available in the parent and child tables.

Example Output:

Parent Table Child Table
P2024 P2024
P2025 P2025
P2026 P2026
Illustrative partition mapping.

6. Advantages of Reference Partitioning

  1. Maintains partition alignment between parent and child tables.
  2. Simplifies partition management.
  3. Can improve performance for suitable parent-child queries.
  4. Makes related data management easier.
  5. Avoids defining separate partitioning rules for the child table.
  6. Useful for managing large related tables.

7. Interview-Ready Answer

Question: What is Reference Partitioning in Oracle?

Answer:

Reference Partitioning in Oracle is a technique in which a child table inherits the partitioning structure of its parent table through a foreign key relationship. For example, if the ORDERS table is partitioned based on ORDER_DATE, the ORDER_ITEMS table can use Reference Partitioning to follow the same partition structure. It helps maintain related data in corresponding partitions and simplifies partition management.

8. Difference Between Range and Reference Partitioning

One of the important Oracle interview questions is the difference between Range Partitioning and Reference Partitioning.

Range Partitioning Reference Partitioning
Based on a range of column values. Based on a parent-child relationship.
Commonly uses date or numeric columns. Uses a foreign key constraint.
Partitions are defined using range boundaries. Child inherits the parent's partitioning structure.
Example: Orders by year. Example: ORDER_ITEMS based on ORDERS.

9. Important Interview Tip

Remember all five partitioning concepts:

Range: Data divided based on ranges.

List: Data divided based on specific values.

Hash: Data distributed using a hashing algorithm.

Interval: Oracle automatically creates new partitions.

Reference: Child table inherits the parent table's partitioning structure.

Conclusion

Reference Partitioning is an important Oracle Database feature used to maintain partition relationships between parent and child tables. It is especially useful in applications containing large related tables, such as ORDERS and ORDER_ITEMS.

Understanding Reference Partitioning, its foreign key relationship, SQL syntax, and practical implementation is important for Oracle SQL and PL/SQL developer interviews.

ORACLE SQL | REFERENCE PARTITIONING | DATABASE PARTITIONING | ORACLE INTERVIEW QUESTIONS

What is interval partitioning

Interval Partitioning in Oracle is an extension of Range Partitioning in which Oracle automatically creates new partitions when data is inserted beyond the existing partition range.

In normal Range Partitioning, we need to manually create new partitions when new data exceeds the existing range.

But in Interval Partitioning, Oracle automatically creates new partitions based on the specified interval.

It is commonly used for date-based tables, such as banking transactions, sales records, and employee attendance.

1. Real-time Example

Suppose we have a TRANSACTIONS table containing banking transaction records.

We want to divide the data month-wise.

Real-time scenario:
Consider a banking application that receives thousands of transactions every day. Instead of manually creating a new partition for every month, we can use Interval Partitioning. Oracle automatically creates new monthly partitions when data arrives for future months.
Partition Data Stored
P_INITIAL Records before 01-Jan-2026
System-generated partition January 2026
System-generated partition February 2026
System-generated partition March 2026
System-generated partition April 2026

Without Interval Partitioning:

  • We need to manually create partitions for upcoming months.
  • DBA maintenance work increases.

With Interval Partitioning:

  • Oracle automatically creates new monthly partitions.
  • No need to manually add every new monthly partition.

2. SQL Example – Create Interval Partitioned Table

Let's create an interval-partitioned table using the transaction_date column.

CREATE TABLE transactions
(
    transaction_id NUMBER,
    customer_name VARCHAR2(100),
    transaction_date DATE,
    amount NUMBER
)
PARTITION BY RANGE (transaction_date)
INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
(
    PARTITION p_initial
    VALUES LESS THAN (DATE '2026-01-01')
);

Explanation:

  • PARTITION BY RANGE (transaction_date) specifies the date column used for partitioning.
  • INTERVAL (NUMTOYMINTERVAL(1, 'MONTH')) tells Oracle to create partitions at monthly intervals.
  • p_initial is the initial range partition.
  • Oracle automatically creates additional monthly partitions when required.
Important: Interval Partitioning requires an initial range partition. The interval is calculated from the transition point defined by the initial partition's upper boundary.

3. Insert Sample Records

Let's insert some sample transaction records into the transactions table.

INSERT INTO transactions
VALUES (101, 'Ravi', DATE '2026-01-15', 5000);

INSERT INTO transactions
VALUES (102, 'Kumar', DATE '2026-02-10', 7000);

INSERT INTO transactions
VALUES (103, 'Raj', DATE '2026-03-20', 9000);

INSERT INTO transactions
VALUES (104, 'Suresh', DATE '2026-04-05', 6000);

COMMIT;

What happens internally?

  • January data goes into the automatically created January interval partition.
  • February data causes Oracle to create a February partition.
  • March data causes Oracle to create a March partition.
  • April data causes Oracle to create an April partition.
Important Point:
The initial partition stores dates before 01-Jan-2026. The first interval partition stores January 2026 records. Oracle creates subsequent monthly partitions automatically as data is inserted.
Transaction ID Customer Name Transaction Date Partition Period
101 Ravi 15-Jan-2026 January 2026
102 Kumar 10-Feb-2026 February 2026
103 Raj 20-Mar-2026 March 2026
104 Suresh 05-Apr-2026 April 2026

4. How to Check the Partitions?

To check the partitions available in the transactions table, execute the following query:

SELECT
    TABLE_NAME,
    PARTITION_NAME,
    HIGH_VALUE
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'TRANSACTIONS'
ORDER BY PARTITION_POSITION;

This query displays the partitions created for the table, including the automatically generated interval partitions.

Interview Tip:
Oracle creates interval partitions automatically when data is inserted into a range beyond the transition point. The partition metadata can be checked using USER_TAB_PARTITIONS.

5. Advantages of Interval Partitioning

  1. Automatically creates new partitions.
  2. Reduces manual DBA maintenance.
  3. Useful for date-based tables.
  4. Makes historical data management easier.
  5. Supports partition pruning for better query performance.
  6. Suitable for regularly growing transaction tables.

6. Interview-Ready Answer

Question: What is Interval Partitioning in Oracle?

Answer:

Interval Partitioning in Oracle is an extension of Range Partitioning. It automatically creates new partitions when data is inserted beyond the existing range, based on a predefined interval. For example, we can create monthly partitions for a banking transaction table. Oracle automatically creates new monthly partitions as new transaction dates arrive, reducing manual maintenance.

7. Difference Between Range and Interval Partitioning

One of the important Oracle interview questions is the difference between Range Partitioning and Interval Partitioning.

Range Partitioning Interval Partitioning
Partitions are manually created. New interval partitions are automatically created.
DBA needs to add future partitions. Oracle creates future partitions automatically.
Uses range boundaries. Uses range boundaries and a predefined interval.
Example: Year-wise partitions. Example: Automatically generated monthly partitions.
Manual partition maintenance is required. Reduces manual partition creation.

8. Important Interview Tip

Remember this simple concept:

Range Partitioning: We manually create partitions.

Interval Partitioning: Oracle automatically creates new partitions based on the specified interval.

Conclusion

Interval Partitioning is an important Oracle Database feature used to automatically manage partitions for continuously growing tables. It is especially useful for date-based transaction tables where new data arrives regularly.

Understanding Interval Partitioning, its SQL syntax, automatic partition creation, and its difference from Range Partitioning is important for Oracle SQL and PL/SQL developer interviews.

ORACLE SQL | INTERVAL PARTITIONING | DATABASE PARTITIONING | ORACLE INTERVIEW QUESTIONS

What is hash partitioning

Hash Partitioning in Oracle is a partitioning technique in which Oracle automatically distributes table records across multiple partitions using a hashing algorithm based on a specified column.

Unlike Range and List Partitioning, we do not manually specify which record belongs to which partition. Oracle decides where to store each record.

It is useful when we want to distribute data evenly across multiple partitions.

1. Real-time Example

Suppose we have an EMPLOYEES table containing 10 lakh records.

We want to divide the employee records into four partitions based on the EMP_ID column.

Real-time scenario:
Consider an organization having millions of employee records. Instead of manually assigning employee records to individual partitions, we can use Hash Partitioning. Oracle automatically distributes the records across four partitions using its internal hashing algorithm.
Partition Records
P1 Employees distributed by Oracle
P2 Employees distributed by Oracle
P3 Employees distributed by Oracle
P4 Employees distributed by Oracle

Oracle automatically distributes the records using its internal hashing algorithm.

2. SQL Example – Create Hash Partitioned Table

Let's create a hash-partitioned table using the EMP_ID column.

CREATE TABLE employees
(
    emp_id NUMBER,
    emp_name VARCHAR2(100),
    department VARCHAR2(30),
    salary NUMBER
)
PARTITION BY HASH (emp_id)
PARTITIONS 4;

Explanation:

  • PARTITION BY HASH (emp_id) specifies the column used for hash partitioning.
  • PARTITIONS 4 creates four partitions.
  • Oracle automatically distributes records across these four partitions.
  • We don't need to specify individual partition values.
Important: In Hash Partitioning, Oracle uses its internal hashing mechanism to determine the partition for each record. We do not manually define partition boundaries or individual column values.

3. Insert Sample Records

Let's insert some sample employee records into the employees table.

INSERT INTO employees
VALUES (101, 'Ravi', 'IT', 50000);

INSERT INTO employees
VALUES (102, 'Kumar', 'HR', 40000);

INSERT INTO employees
VALUES (103, 'Raj', 'FINANCE', 60000);

INSERT INTO employees
VALUES (104, 'Suresh', 'SALES', 45000);

INSERT INTO employees
VALUES (105, 'Ajay', 'IT', 55000);

COMMIT;

Oracle automatically distributes these records across the four partitions based on the EMP_ID column.

Important Point:
We cannot predict the exact partition assignment simply by looking at the employee ID. Oracle uses its internal hashing algorithm to determine the destination partition.

4. How to Retrieve Data from a Particular Partition?

To retrieve records from a particular partition, use the PARTITION clause.

SELECT *
FROM employees
PARTITION (SYS_P101);
Note: SYS_P101 is only an illustrative partition name. Actual partition names may differ in your database. Always check the partition names before querying a specific partition.

To check the available partitions:

SELECT
    TABLE_NAME,
    PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'EMPLOYEES';
Example Output:

TABLE_NAME PARTITION_NAME
EMPLOYEES SYS_P101
EMPLOYEES SYS_P102
EMPLOYEES SYS_P103
EMPLOYEES SYS_P104
Illustrative output only. Actual partition names depend on the table definition.

5. Advantages of Hash Partitioning

  1. Distributes data across multiple partitions automatically.
  2. Helps distribute data more evenly.
  3. Reduces the possibility of data concentration in a single partition.
  4. Useful for managing large tables.
  5. Can improve performance for suitable queries and workloads.
  6. Does not require manually defining value ranges or categories.

6. Interview-Ready Answer

Question: What is Hash Partitioning in Oracle?

Answer:

Hash Partitioning in Oracle is a technique used to distribute table records across multiple partitions using an Oracle hashing algorithm based on a specified column. Oracle automatically decides which partition should store each record. It is useful for distributing large volumes of data across multiple partitions and improving data management.

7. Difference Between Range, List, and Hash Partitioning

One of the important Oracle interview questions is the difference between Range, List, and Hash Partitioning.

Range Partitioning List Partitioning Hash Partitioning
Based on ranges of values. Based on specific values. Based on a hashing algorithm.
Year-wise data. Department-wise data. Automatically distributed data.
Uses VALUES LESS THAN. Uses VALUES. Uses PARTITIONS.
Example: Transaction date. Example: Department. Example: Employee ID.
Data is divided based on value boundaries. Data is divided based on specified values. Data is distributed automatically by Oracle.

8. Important Interview Tip

Remember these three concepts:

Range = Data divided based on ranges.

List = Data divided based on specific values.

Hash = Oracle automatically distributes data across partitions.

Conclusion

Hash Partitioning is an important partitioning technique in Oracle Database. It is especially useful when we want to distribute large volumes of data across multiple partitions without manually defining ranges or categories.

Understanding Hash Partitioning, its SQL syntax, and how Oracle distributes records is important for Oracle SQL and PL/SQL developer interviews.

ORACLE SQL | HASH PARTITIONING | DATABASE PARTITIONING | ORACLE INTERVIEW QUESTIONS