Solved

Possible PL/SQL Script ?

Posted on 2014-04-08
3
390 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
Comment Utility
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
Comment Utility
If you want to execute this then add a line
Execute immediate var_sql;
Before end loop; statement
0
 

Author Closing Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

771 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

12 Experts available now in Live!

Get 1:1 Help Now