Crear particionamiento interval y convertir una tabla range existente a interval
OracleParticionamientoComando
-- New table: a partition is created automatically for each month
CREATE TABLE customer_app.measurements (
ts DATE NOT NULL,
sensor_id NUMBER,
value NUMBER)
PARTITION BY RANGE (ts) INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
( PARTITION p_first VALUES LESS THAN (DATE '2026-01-01') );
-- Convert an existing range table to interval (there must be no MAXVALUE partition):
ALTER TABLE customer_app.sale_part SET INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'));
-- Back to range: ALTER TABLE customer_app.sale_part SET INTERVAL ();
-- Rename a system-named partition to a meaningful name:
ALTER TABLE customer_app.measurements RENAME PARTITION FOR (DATE '2026-03-15') TO p2026_03;
-- Check:
SELECT partition_name, partition_position, interval, high_value
FROM dba_tab_partitions
WHERE table_owner = 'CUSTOMER_APP' AND table_name = 'MEASUREMENTS'
ORDER BY partition_position;
SELECT table_name, partitioning_type, interval
FROM dba_part_tables
WHERE owner = 'CUSTOMER_APP';Qué hace
El particionamiento interval crea automáticamente una partición nueva cuando llega la primera fila más allá del último límite, eliminando los errores ORA-14400 causados por olvidar la partición del mes siguiente. SET INTERVAL convierte una tabla range existente sin mover datos.
Cuándo usarlo
Para tablas que crecen por fecha, como series temporales, logs y pedidos, y para reducir los scripts de mantenimiento de particiones.
Precaución
Requiere la opción Partitioning (EE con costo adicional). La clave de partición debe ser una única columna NUMBER/DATE/TIMESTAMP; antes hay que quitar la partición MAXVALUE. Una fecha errónea o extrema (p. ej., el año 9999) abre una partición lejana y distorsiona la numeración de particiones; con intervalos estrechos puede acercarse al límite de 1,048,575 particiones (ORA-14300), así que valide las fechas en la aplicación. Las particiones automáticas van al tablespace por defecto de la tabla (diríjalas con STORE IN).