Solved

Possible PL/SQL Script ?

Posted on 2014-04-08
3
395 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to recover a database from a user managed backup

776 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