Tuesday, 8 September 2015

NTILE FUNCTION : LIFE SAVER ( Chunks DATA into Buckets )

I had Situation where I have Devide rows into Buckets. Where NTILE function did for me.  I had situation where 2 TB Tables needs to copy which is having LOB COLUMNS as well. DATAPUMP and TRADITIONAL export taking very long time.  So we decided to chucks the rows into buckets equally and Insert the data between rowids each time with parallel. Here is NTILE command Which I used to devide.

-- In below query I divided Rows into 256 Chucks by using NTILE.

 spool /XXXXXXXXXXXXXX/ntile_bucket.list
set echo off feedback off trimspool on linesize 200 pages 0 heading off


select min(ROW_ID)||'|'||max(ROW_ID)||'|'||count(*)||'|'||grp_nbr
from
(
select ROW_ID, ntile(256) over (order by ROW_ID) grp_nbr
from (select rowid row_id from  SCHEMA_NAME.TABLE_NAME )
)
group by grp_nbr order by grp_nbr;
spool off;



OUTPUT:-




NTILE FUNCTION is very useful while processing/copying/Moving  the data into chucks .

No comments:

Post a Comment