Create a stored procedure to measure a table usage : Utility Procedure « Stored Procedure Function « Oracle PL / SQL

Oracle PL / SQL
1. Aggregate Functions
2. Analytical Functions
3. Char Functions
4. Constraints
5. Conversion Functions
6. Cursor
7. Data Type
8. Date Timezone
9. Hierarchical Query
10. Index
11. Insert Delete Update
12. Large Objects
13. Numeric Math Functions
14. Object Oriented Database
15. PL SQL
16. Regular Expressions
17. Report Column Page
18. Result Set
19. Select Query
20. Sequence
21. SQL Plus
22. Stored Procedure Function
23. Subquery
24. System Packages
25. System Tables Views
26. Table
27. Table Joins
28. Trigger
29. User Previliege
30. View
31. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL / SQL » Stored Procedure Function » Utility Procedure 
Create a stored procedure to measure a table usage
 
SQL>
SQL> set echo on
SQL>
SQL>
SQL> create table t x int, y char(1000default 'x' );

Table created.

SQL>
SQL> create or replace procedure measure_usage
  2  as
  3      l_free_blks                 number;
  4      l_total_blocks              number;
  5      l_total_bytes               number;
  6      l_unused_blocks             number;
  7      l_unused_bytes              number;
  8      l_LastUsedExtFileId         number;
  9      l_LastUsedExtBlockId        number;
 10      l_LAST_USED_BLOCK           number;
 11      procedure get_data is
 12      begin
 13          dbms_space.free_blocks
 14          segment_owner     =>  USER,
 15            segment_name      => 'T',
 16            segment_type      => 'TABLE',
 17            FREELIST_group_id => 0,
 18            free_blks         => l_free_blks );
 19
 20          dbms_space.unused_space
 21          segment_owner     => USER,
 22            segment_name      => 'T',
 23            segment_type      => 'TABLE',
 24            total_blocks      => l_total_blocks,
 25            total_bytes       => l_total_bytes,
 26            unused_blocks     => l_unused_blocks,
 27            unused_bytes      => l_unused_bytes,
 28            LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
 29            LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
 30            LAST_USED_BLOCK => l_last_used_block ;
 31
 32
 33          dbms_output.put_lineL_free_blks || ' on FREELIST, ' ||
 34                                to_number(l_total_blocks-l_unused_blocks-||
 35                                ' used by table' );
 36      end;
 37  begin
 38      for i in .. 10
 39      loop
 40          dbms_output.put'insert ' || to_char(i,'00') || ' ' );
 41          get_data;
 42          insert into t (xvalues );
 43          commit ;
 44      end loop;
 45
 46
 47      for i in .. 10
 48      loop
 49          dbms_output.put'update ' || to_char(i,'00') || ' ' );
 50          get_data;
 51          update t set y = null where x = i;
 52          commit;
 53      end loop;
 54  end;
 55  /

Procedure created.

SQL>
SQL> exec measure_usage
insert  00 0 on FREELIST, used by table
insert  01 1 on FREELIST, used by table
insert  02 1 on FREELIST, used by table
insert  03 1 on FREELIST, used by table
insert  04 1 on FREELIST, used by table
insert  05 1 on FREELIST, used by table
insert  06 1 on FREELIST, used by table
insert  07 1 on FREELIST, used by table
insert  08 1 on FREELIST, used by table
insert  09 1 on FREELIST, used by table
insert  10 1 on FREELIST, used by table
update  00 1 on FREELIST, used by table
update  01 1 on FREELIST, used by table
update  02 1 on FREELIST, used by table
update  03 1 on FREELIST, used by table
update  04 2 on FREELIST, used by table
update  05 2 on FREELIST, used by table
update  06 2 on FREELIST, used by table
update  07 2 on FREELIST, used by table
update  08 2 on FREELIST, used by table
update  09 2 on FREELIST, used by table
update  10 2 on FREELIST, used by table

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> drop table t;

Table dropped.

SQL>
SQL> --

 
Related examples in the same category
1. Assert procedure
2. Use stored procedure to output table content
3. emp table lookup
4. Use stored procedure to log message
5. Procedure does not count space
6. File dump procedure
7. Copy tables
8. Count credits
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.