?
Solved

Possible PL/SQL Script ?

Posted on 2014-04-08
3
Medium Priority
?
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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 information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

777 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