sql >> Base de Datos >  >> RDS >> Oracle

SQL:¿Cómo dividiría 100,000 registros de una tabla de Oracle en 5 partes?

Si solo desea asignar valores del 1 al 5 a grupos de tamaño básicamente igual, utilice ntile() :

select t.*, ntile(5) over (order by NULL) as num
from (select t.*
      from t
      where rownum <= 100000
     ) t;

Si desea insertar en 5 tablas diferentes, use insert all :

insert all
    when num = 1 then into t1
    when num = 2 then into t2
    when num = 3 then into t3
    when num = 4 then into t4
    when num = 5 then into t5
    select t.*, ntile(5) over (order by NULL) as num
    from (select t.*
          from t
          where rownum <= 100000
         ) t;