Oracle Partitioning: useful scripts

August 24, 2009 – 10:14 am

Query number of records in each partition of the table:

SET SERVEROUTPUT ON SIZE 100000;
DECLARE
CURSOR c1
IS
SELECT table_name,
partition_name
FROM all_tab_partitions
WHERE table_name = 'MCP_CDR_HIST' order by partition_name asc;

v_sql VARCHAR2(2000);
temp_var NUMBER:=0;
BEGIN
dbms_output.put_line('Start');
FOR rec IN c1
LOOP
EXECUTE immediate 'select count(*) from '||rec.table_name||' partition('||rec.partition_name||')' INTO temp_var;
dbms_output.put_line('The Partition '||rec.partition_name||' of table '||rec.table_name||' has '||temp_var||' rows');
END LOOP;
dbms_output.put_line('END');
END;

No TweetBacks yet. (Be the first to Tweet this post)
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • TwitThis
  1. One Response to “Oracle Partitioning: useful scripts”

  2. Hey David, are you turning into a dba ;-) just kidding. Very useful post tho, thanks.

    By Nick Zhu on Aug 25, 2009

Post a Comment