Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Possible PL/SQL Script ?

Posted on 2014-04-08
3
Medium Priority
?
412 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

604 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