Con estos datos de prueba
INSERT INTO foos VALUES (1234, SYSDATE);
INSERT INTO foos VALUES (1235, SYSDATE);
INSERT INTO foos VALUES (1236, SYSDATE);
Como se describe aquí https://jonathanlewis.wordpress.com/2009/11 /21/ora_hash-function/
obtienes
with hsh as (
select BATCH_ID, ora_hash(BATCH_ID, 3)+1 subpartition_position from foos)
select BATCH_ID, SUBPARTITION_POSITION,
(select subpartition_name from user_tab_subpartitions where table_name = 'FOOS' and SUBPARTITION_POSITION = hsh.SUBPARTITION_POSITION) subpartition_name
from hsh;
BATCH_ID SUBPARTITION_POSITION SUBPARTITION_NAME
---------- --------------------- ------------------------------
1236 1 R0_H0
1235 3 R0_H2
1234 4 R0_H3
Tenga en cuenta que el parámetro 3 en ora_hash
es el número de (sub)particiones restado por 1. (=4-1). Tendrá que realizar un procesamiento adicional si el número de particiones no es una potencia de dos (lo que no se recomienda) como se describe en la referencia.
Puede verificar el resultado con una consulta de partición explícita como se muestra a continuación
select * from foos subpartition( R0_H0 ); -- 1236
select * from foos subpartition( R0_H1 ); -- empty
select * from foos subpartition( R0_H2 ); -- 1235
select * from foos subpartition( R0_H3 ); -- 1234
Y por supuesto también funciona para claves nuevas, nuevas para 1237 que no está en la tabla.
with hsh as (
select 1237 BATCH_ID, ora_hash(1237, 3)+1 subpartition_position from dual)
select BATCH_ID, SUBPARTITION_POSITION,
(select subpartition_name from user_tab_subpartitions where table_name = 'FOOS' and SUBPARTITION_POSITION = hsh.SUBPARTITION_POSITION) subpartition_name
from hsh;
BATCH_ID SUBPARTITION_POSITION SUBPARTITION_NAME
---------- --------------------- ------------------------------
1237 2 R0_H1
La subpartición "predicha" es R0_H1
, veamos adónde irá el INSERT:
INSERT INTO foos VALUES (1237, SYSDATE);
select * from foos subpartition( R0_H1 ); -- 1237
Pero utilícelo con precaución, ya que es una característica no documentada de la OMI...