Solved

Possible PL/SQL Script ?

Posted on 2014-04-08
3
393 Views
Last Modified: 2014-04-08
I've got a table with about 600 partitions.  Somebody here wants this get_compression_ratio run on databases.  If i understand this correct i need to run once for each of these partitions.  
Can I get a script that will look at dba_-tab_partitions and select partition_name
where user will always be 'auser' , scratchtbsname will always be scratch, tablename will always be tablea and partition name will come from dba_tab_partitions.


set serveroutput on
declare
v_blkcnt_cmp pls_integer;
v_blkcnt_uncmp pls_integer;
v_row_cmp pls_integer;
v_row_uncmp pls_integer;
v_cmp_ratio number;
v_comptype_str varchar2(60);
begin
dbms_compression.get_compression_ratio(
scratchtbsname => upper('&ScratchTBS'),
ownname => user,
tabname => upper('&TableName'),
partname => NULL,
comptype => dbms_compression.comp_for_query_high,
blkcnt_cmp => v_blkcnt_cmp,
blkcnt_uncmp => v_blkcnt_uncmp,
row_cmp => v_row_cmp,
row_uncmp => v_row_uncmp,
cmp_ratio => v_cmp_ratio,
comptype_str => v_comptype_str, subset_numrows=>&num_rows );
dbms_output.put_line('Estimated Compression Ratio: '||to_char(v_cmp_ratio));
dbms_output.put_line('Blocks used by compressed sample: '||to_char(v_blkcnt_cmp));
dbms_output.put_line('Blocks used by uncompressed sample: '||to_char(v_blkcnt_uncmp));
end;
0
Comment
Question by:xoxomos
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 500 total points
ID: 39985461
this will generate the script  based on your script,  placed some values by using dba_Tab_partitions,
also you can modify the user name and comment out the part select user from dual if not needed and can hard code the table name if you want..

if you place the values v_blkcnt_cmp,v_row_cmp those will get subsituted below, else it will place null there

set serveroutput on;

DECLARE
   v_blkcnt_cmp     PLS_INTEGER;
   v_blkcnt_uncmp   PLS_INTEGER;
   v_row_cmp        PLS_INTEGER;
   v_row_uncmp      PLS_INTEGER;
   v_cmp_ratio      NUMBER;
   v_comptype_str   VARCHAR2 (60);
   var_sql          VARCHAR2 (10000);

   CURSOR c1
   IS
      SELECT *
        FROM dba_tab_partitions
       WHERE table_name = 'COSTS';

   v_user           VARCHAR2 (100);
BEGIN
   SELECT USER
     INTO v_user
     FROM DUAL;

   FOR l1 IN c1
   LOOP
      var_sql := 'dbms_compression.get_compression_ratio(scratchtbsname => ';
      var_sql :=
            var_sql || CHR (39) || UPPER (l1.tablespace_name) || CHR (39)
            || ',';
      var_sql :=
               var_sql || 'ownname =>' || CHR (39) || v_user || CHR (39)
               || ',';
      var_sql :=
            var_sql
         || 'tabname => '
         || CHR (39)
         || UPPER (l1.table_name)
         || CHR (39)
         || ',';
      var_sql :=
            var_sql
         || 'partname => NULL,comptype => dbms_compression.comp_for_query_high,';
      var_sql := var_sql || 'blkcnt_cmp => ' || v_blkcnt_cmp || ',';
      var_sql := var_sql || 'blkcnt_uncmp =>' || v_blkcnt_uncmp || ',';
      var_sql := var_sql || 'row_cmp => ' || v_row_cmp || ',';
      var_sql := var_sql || 'row_uncmp =>' || v_row_uncmp || ',';
      var_sql := var_sql || ' cmp_ratio => ' || v_cmp_ratio || ',';
      var_sql := var_sql || 'comptype_str => ' ||chr(39)|| v_comptype_str ||chr(39)|| ',';
      var_sql := var_sql || 'subset_numrows=>' || l1.num_rows || ' );';
--dbms_output.put_line('Estimated Compression Ratio: '||to_char(v_cmp_ratio));
--dbms_output.put_line('Blocks used by compressed sample: '||to_char(v_blkcnt_cmp));
--dbms_output.put_line('Blocks used by uncompressed sample: '||to_char(v_blkcnt_uncmp));
      DBMS_OUTPUT.put_line ('exec ' || var_sql);
      DBMS_OUTPUT.put_line ('   ');
   END LOOP;
END;
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 39986347
If you want to execute this then add a line
Execute immediate var_sql;
Before end loop; statement
0
 

Author Closing Comment

by:xoxomos
ID: 39986503
Thanks Wizard, will let you know how i fare :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now