Checking free space in tables across all the tables in database

Hello ,
I have the below script which Gives the Free Blocks , Unused Blocks for the Tables of the Current User ( In which schema the script is run). How can this be modified so that it loops through all the schema tables in the database. ( Got this script from tom kytes blog)
create or replace type show_space_type
as object
( owner varchar2(30),
segment_name varchar2(30),
partition_name varchar2(30),
segment_type varchar2(30),
free_blocks number,
total_blocks number,
total_bytes number,
unused_blocks number,
unused_bytes number,
last_used_ext_fileid number,
last_used_ext_blockid number,
last_used_block number
create or replace type show_space_table_type
as table of show_space_type
create or replace
function show_space_for
( p_segname in varchar2,
p_owner in varchar2 default user,
p_type in varchar2 default 'TABLE',
p_partition in varchar2 default NULL )
return show_space_table_type
authid CURRENT_USER
PIPELINED
as
pragma autonomous_transaction;
type rc is ref cursor;
l_cursor rc;
l_free_blks number;
l_total_blocks number;
l_total_bytes number;
l_unused_blocks number;
l_unused_bytes number;
l_LastUsedExtFileId number;
l_LastUsedExtBlockId number;
l_last_used_block number;
l_sql long;
l_conj varchar2(7) default ' where ';
l_owner varchar2(30);
l_segment_name varchar2(30);
l_segment_type varchar2(30);
l_partition_name varchar2(30);
procedure add_predicate( p_name in varchar2, p_value in varchar2 )
as
begin
if ( instr( p_value, '%' ) > 0 )
then
l_sql := l_sql || l_conj || p_name || ' like ''' || upper(p_value) || '''';
l_conj := ' and ';
elsif ( p_value is not null )
then
l_sql := l_sql || l_conj || p_name || ' = ''' || upper(p_value) || '''';
l_conj := ' and ';
end if;
end;
begin
l_sql := 'select owner, segment_name, segment_type, partition_name
from dba_segments ';
add_predicate( 'segment_name', p_segname );
add_predicate( 'owner', p_owner );
add_predicate( 'segment_type', p_type );
add_predicate( 'partition', p_partition );
execute immediate 'alter session set cursor_sharing=force';
open l_cursor for l_sql;
execute immediate 'alter session set cursor_sharing=exact';
loop
fetch l_cursor into l_owner, l_segment_name, l_segment_type, l_partition_name;
dbms_output.put_line( l_segment_name || ',' || l_segment_type );
exit when l_cursor%notfound;
begin
dbms_space.free_blocks
( segment_owner => l_owner,
segment_name => l_segment_name,
segment_type => l_segment_type,
partition_name => l_partition_name,
freelist_group_id => 0,
free_blks => l_free_blks );
dbms_space.unused_space
( segment_owner => l_owner,
segment_name => l_segment_name,
segment_type => l_segment_type,
partition_name => l_partition_name,
total_blocks => l_total_blocks,
total_bytes => l_total_bytes,
unused_blocks => l_unused_blocks,
unused_bytes => l_unused_bytes,
LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
LAST_USED_BLOCK => l_LAST_USED_BLOCK );
pipe row ( show_space_type( l_owner, l_segment_name, l_partition_name,
l_segment_type, l_free_blks, l_total_blocks,l_total_bytes, l_unused_blocks, l_unused_bytes,
l_lastUsedExtFileId, l_LastUsedExtBlockId, l_last_used_block ) );
exception
when others then null;
end;
end loop;
close l_cursor;
return;
end;
select SEGMENT_NAME, SEGMENT_TYPE, FREE_BLOCKS,TOTAL_BLOCKS,UNUSED_BLOCKS , (TOTAL_BYTES)/1024/1024 "Total MB", (UNUSED_BYTES)/1024/1024 "UNUSED MB"
from table( show_space_for( '%',user,'%' ) );
I am not really good at using the pl/sql . I was thinking to use a cursor to loop through the dba_users but not sure where and how I can insert it the code.
Thanks for any help.

http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1336002638218#1339720300346849060
Do a search yourself on AskTom.
Chances are you don't need to do anything at all here, but it depends on a lot of things...
Also search the Database-General forum on this subject:
General Database Discussions
Oracle Onine Documentation:
http://www.oracle.com/pls/db102/homepage
Just do some quick searches from there as well.

Similar Messages

  • Cannot display all the tables of the schema!!!

    Hi:
    I use the oracle sql developer on the windows xp, I found that the tables tab cannot display all the tables of the schema owner, I use the sql "select count(*) from user_tables" I found the result is more than the tab can be display, and I also press the "show more" already.... does anyone can help me ???

    Similarly, I have 852 tables owned by the connected user (selected count from user_tables and checked the user tables report which has this many records returned), but when I double-click on the "Show More" and select Show All, I only get approximately 375 tables listed.
    It doesn't help that the sorting is different - ie ASF_ comes before ASFB in the connection pane but the other way around in the report.
    However, it looks as though the problem is that tables that are not analysed (based on the report data in DATE_LAST_ANALYZED) are not being displayed under the Table node.

  • What r all the tables used for this report. please reply

    hai,
    what r all the tables used for this report.
    report :
    <b>
    •     Report to display all finished goods that go out-of-stock. Developed a drill down report for materials details (totals and subtotals for material stock values by material group and material type).</b>
    thanks in advance

    hi Ashok,
    Check this out
    http://www.allsaplinks.com/tables.html
    http://www.sapgenie.com/abap/tables.htm
    Regards,
    Santosh

  • Script to generate all the tables and objects in a schema

    how to write a script to generate all the tables and objects in a schema.
    with toad the no of tables generated is not matching when i check from schema .

    Dear Sidhant,
    Try this script:
    set termout off
    set feedback off
    set serveroutput on size 100000
    spool ddl_schema.sql
    begin
    dbms_output.put_line('--');
    dbms_output.put_line('-- DROP TABLES --');
    dbms_output.put_line('--');
        for rt in (select tname from tab order by tname) loop
            dbms_output.put_line('DROP TABLE '||rt.tname||' CASCADE CONSTRAINTS;');
        end loop;
    end;
    declare
        v_tname  varchar2(30);
        v_cname  char(32);
        v_type     char(20);
        v_null   varchar2(10);
        v_maxcol number;
        v_virg     varchar2(1);
    begin
    dbms_output.put_line('--');
    dbms_output.put_line('-- CREATE TABLES --');
    dbms_output.put_line('--');
        for rt in (select table_name from user_tables order by 1) loop
            v_tname:=rt.table_name;
            v_virg:=',';
            dbms_output.put_line('CREATE TABLE '||v_tname||' (');
            for rc in (select table_name,column_name,data_type,data_length,
                                data_precision,data_scale,nullable,column_id
                    from user_tab_columns tc
                    where tc.table_name=rt.table_name
                    order by table_name,column_id) loop
                        v_cname:=rc.column_name;
                        if rc.data_type='VARCHAR2' then
                            v_type:='VARCHAR2('||rc.data_length||')';
                        elsif rc.data_type='NUMBER' and rc.data_precision is null and
                                             rc.data_scale=0 then
                            v_type:='INTEGER';
                        elsif rc.data_type='NUMBER' and rc.data_precision is null and
                                         rc.data_scale is null then
                            v_type:='NUMBER';
                        elsif rc.data_type='NUMBER' and rc.data_scale='0' then
                            v_type:='NUMBER('||rc.data_precision||')';
                        elsif rc.data_type='NUMBER' and rc.data_scale<>'0' then
                            v_type:='NUMBER('||rc.data_precision||','||rc.data_scale||')';
                        elsif rc.data_type='CHAR' then
                             v_type:='CHAR('||rc.data_length||')';
                        else v_type:=rc.data_type;
                        end if;
                        if rc.nullable='Y' then
                            v_null:='NULL';
                        else
                            v_null:='NOT NULL';
                        end if;
                        select max(column_id)
                            into v_maxcol
                            from user_tab_columns c
                            where c.table_name=rt.table_name;
                        if rc.column_id=v_maxcol then
                            v_virg:='';
                        end if;
                        dbms_output.put_line (v_cname||v_type||v_null||v_virg);
            end loop;
            dbms_output.put_line(');');
        end loop;
    end;
    declare
        v_virg        varchar2(1);
        v_maxcol    number;
    begin
    dbms_output.put_line('--');
    dbms_output.put_line('-- PRIMARY KEYS --');
    dbms_output.put_line('--');
        for rcn in (select table_name,constraint_name
                from user_constraints
                where constraint_type='P'
                order by table_name) loop
            dbms_output.put_line ('ALTER TABLE '||rcn.table_name||' ADD (');
            dbms_output.put_line ('CONSTRAINT '||rcn.constraint_name);
            dbms_output.put_line ('PRIMARY KEY (');
            v_virg:=',';
            for rcl in (select column_name,position
                    from user_cons_columns cl
                    where cl.constraint_name=rcn.constraint_name
                    order by position) loop
                select max(position)
                    into v_maxcol
                    from user_cons_columns c
                    where c.constraint_name=rcn.constraint_name;
                if rcl.position=v_maxcol then
                    v_virg:='';
                end if;
                dbms_output.put_line (rcl.column_name||v_virg);
            end loop;
            dbms_output.put_line(')');
            dbms_output.put_line('USING INDEX );');
        end loop;
    end;
    declare
        v_virg        varchar2(1);
        v_maxcol    number;
        v_tname        varchar2(30);
    begin
    dbms_output.put_line('--');
    dbms_output.put_line('-- FOREIGN KEYS --');
    dbms_output.put_line('--');
        for rcn in (select table_name,constraint_name,r_constraint_name
                from user_constraints
                where constraint_type='R'
                order by table_name) loop
            dbms_output.put_line ('ALTER TABLE '||rcn.table_name||' ADD (');
            dbms_output.put_line ('CONSTRAINT '||rcn.constraint_name);
            dbms_output.put_line ('FOREIGN KEY (');
            v_virg:=',';
            for rcl in (select column_name,position
                    from user_cons_columns cl
                    where cl.constraint_name=rcn.constraint_name
                    order by position) loop
                select max(position)
                    into v_maxcol
                    from user_cons_columns c
                    where c.constraint_name=rcn.constraint_name;
                if rcl.position=v_maxcol then
                    v_virg:='';
                end if;
                dbms_output.put_line (rcl.column_name||v_virg);
            end loop;
            select table_name
                into v_tname
                from user_constraints c
                where c.constraint_name=rcn.r_constraint_name;
            dbms_output.put_line(') REFERENCES '||v_tname||' (');
            select max(position)
                    into v_maxcol
                    from user_cons_columns c
                    where c.constraint_name=rcn.r_constraint_name;
            v_virg:=',';
            select max(position)
                into v_maxcol
                from user_cons_columns c
                where c.constraint_name=rcn.r_constraint_name;
            for rcr in (select column_name,position
                    from user_cons_columns cl
                    where rcn.r_constraint_name=cl.constraint_name
                    order by position) loop
                if rcr.position=v_maxcol then
                    v_virg:='';
                end if;
                dbms_output.put_line (rcr.column_name||v_virg);
            end loop;
            dbms_output.put_line(') );');
        end loop;
    end;
    begin
    dbms_output.put_line('--');
    dbms_output.put_line('-- DROP SEQUENCES --');
    dbms_output.put_line('--');
        for rs in (select sequence_name
                from user_sequences
                where sequence_name like 'SQ%'
                order by sequence_name) loop
            dbms_output.put_line('DROP SEQUENCE '||rs.sequence_name||';');
        end loop;
    dbms_output.put_line('--');
    dbms_output.put_line('-- CREATE SEQUENCES --');
    dbms_output.put_line('--');
        for rs in (select sequence_name
                from user_sequences
                where sequence_name like 'SQ%'
                order by sequence_name) loop
            dbms_output.put_line('CREATE SEQUENCE '||rs.sequence_name||' NOCYCLE;');
        end loop;
    end;
    declare
        v_virg        varchar2(1);
        v_maxcol    number;
    begin
    dbms_output.put_line('--');
    dbms_output.put_line('-- INDEXES --');
    dbms_output.put_line('--');
        for rid in (select index_name, table_name
                from user_indexes
                where index_name not in (select constraint_name from user_constraints)
                    and index_type<>'LOB'
                order by index_name) loop
            v_virg:=',';
            dbms_output.put_line('CREATE INDEX '||rid.index_name||' ON '||rid.table_name||' (');
            for rcl in (select column_name,column_position
                    from user_ind_columns cl
                    where cl.index_name=rid.index_name
                    order by column_position) loop
                select max(column_position)
                    into v_maxcol
                    from user_ind_columns c
                    where c.index_name=rid.index_name;
                if rcl.column_position=v_maxcol then
                    v_virg:='';
                end if;
                dbms_output.put_line (rcl.column_name||v_virg);
            end loop;
            dbms_output.put_line(');');
        end loop;
    end;
    spool off
    set feedback on
    set termout on Best Regards,
    Francisco Munoz Alvarez
    www.oraclenz.com

  • Search in database in all the tables

    Hi friends,
    I want to search following text in database in all the tables :
    Paris-Murex BO for BNL- Panorama(Roma) / BNL-Panorama for Paris-Murex BO(Roma)
    above text is thr in our client site which is getting retrieved from database, I know the database instance name but but dont know from which table this value (text) is comming from.
    please help it's urgent!!!

    This is a depressingly common request. Why are there so many shonky undocumented applications out there?
    Anyway, the solution for a one-off exercise is this brute force approach. It's not pretty and the performance will be Teh Suck, but it will find the string. If you think that the string might be in more than one column you should remove the EXIT and let the thing grind on for as long as it takes.
    set serveroutput on
    declare
        n number;
    begin
        for r in ( select owner, table_name, column_name
                   from all_tab_columns
                   where owner not in ('SYS', 'SYSTEM')
                   and   data_type in ('CHAR', 'VARCHAR2')
                   and   data_length >= 43 )
        loop
            dbms_output.put_line('checking!!'||r.owner||'.'||r.table_name||'.'||r.column_name);
            begin
                execute immediate 'select 1 from '||r.owner||'.'||r.table_name
                              ||' where '||r.column_name||' like ''%Paris-Murex BO for BNL- Panorama(Roma) / BNL-Panorama for Paris-Murex BO(Roma)%'''
                              ||' and rownum = 1'
                into n;
                dbms_output.put_line('found it!!'||r.owner||'.'||r.table_name||'.'||r.column_name);
                exit;
            exception
                when no_data_found
                then
                    null;
            end;
        end loop;
    end;
    /If you have CLOBs and BLOBs you want to check as well then you'll need to run through a second query using CONTAINS(). Implementing that is left as an exercise for the reader.
    Note that if you want to do this on a regular basis then you need a completely different, more architectural approach.
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • Significance of 3 flags used in almost all the tables

    Hello everyone,
    Please let me know the significance of flags used in almost all the tables in BI/BW.
    If the flags are initial, what does that signify ?
    CHCKFL : Flag: Value in check tables
    DATAFL : Flag: Value in dimension or available as attribute
    INCFL     : Flag: Value is built into all inclusion tables
    If CHCKFL is initial, means this record is not maintained in Check table, and so i wont see it if i search it in its InfoObject (That conatins this table).
    How should i retrieve such a record?
    Thanks
    Edited by: shalaxy s on Nov 19, 2009 5:44 PM

    Hi,
    These flags are a kind of "where used" flags.
    CHCKFL, DATAFL
    Re: Meaning of CHCKFL    DATAFL  INCFL   in sid table of  IO
    INCFL
    Used in inclusion tables of external hierarchies
    These fields are also initial when you delete master data of a characteristic with option not to delete related SIDs.
    Hope this helps
    Joe

  • To Get all the Table Names

    Hi All
    I have nearly 70 procedures in my database.
    I want to get all the distinct table names used in the 70 procedures.
    Is it possible?
    Note:
    All the table names are prefixed by schema name like DEVSRC.table_name.
    Please advice
    Thanks
    Jo

    Johney  wrote:
    Hi VT
    One doubt.
    This query will give the table names of only select stmt used in the procedure
    or
    List of table names that are with in any DML operations inside the procedure?
    Thanks
    JoIt will give all the table either used in select or in any DML..
    You can also check by creating a temp proc
    SQL> drop procedure proc_test;
    Procedure dropped.
    SQL> select name, referenced_name, dependency_type from user_dependencies
      2  where type = 'PROCEDURE' and referenced_type = 'TABLE' and name='PROC_TEST';
    no rows selected
    SQL> create or replace
      2  PROCEDURE proc_test
      3  IS
      4  v_ID    number;
      5  v_PRID  number;
      6  v_PRLID number;
      7  v_DATERECEIVED date;
      8  Cursor C1 is
      9  select * from table_c;
    10   BEGIN
    11   open c1;
    12     LOOP
    13      FETCH c1 INTO v_ID,v_PRID,v_PRLID,v_DATERECEIVED;
    14      EXIT WHEN c1%NOTFOUND;
    15      insert into table_b values(v_ID,v_PRID,v_PRLID,v_DATERECEIVED);
    16      Commit;
    17     END LOOP;
    18   CLOSE C1;
    19   END;
    20  /
    Procedure created.
    SQL> select name, referenced_name, dependency_type from user_dependencies
      2  where type = 'PROCEDURE' and referenced_type = 'TABLE' and name='PROC_TEST';
    NAME
    REFERENCED_NAME                                                  DEPE
    PROC_TEST
    TABLE_B                                                          HARD
    PROC_TEST
    TABLE_C                                                          HARD
    SQL> Regards
    Umesh

  • How to find accurate number of Rows, and size of all the tables of a Schema

    HI,
    How to find the accurate number of Rows, and size of all the tables of a Schema ????
    Thanks.

    SELECT t.table_name AS "Table Name",
    t.num_rows AS "Rows",
    t.avg_row_len AS "Avg Row Len",
    Trunc((t.blocks * p.value)/1024) AS "Size KB",
    t.last_analyzed AS "Last Analyzed"
    FROM dba_tables t,
    v$parameter p
    WHERE t.owner = Decode(Upper('&1'), 'ALL', t.owner, Upper('&1'))
    AND p.name = 'db_block_size'
    ORDER by 4 desc nulls last;
    ## Gather schema stats
    begin
    dbms_stats.gather_schema_stats(ownname=>'SYSLOG');
    end;
    ## Gather a particular table stats of a schema
    begin
    DBMS_STATS.gather_table_stats(ownname=>'syslog',tabname=>'logs');
    end;
    http://www.oradev.com/create_statistics.jsp
    Hope this will work.
    Regards
    Asif Kabir
    -- Mark the answer as correct/helpful

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • What are all the tables used for this report:

    hi
    what are all the tables used for this report:
    report:
    •     <b>Stock Report, which will give opening balance, receipt, issue, and closing balance for any given Duration for any material.</b>
    thanks in advance

    Tables: MSEG, MKPF, MARD.
    FOR REFERENCE SEE TRANSACTION : MB5B.
    Message was edited by: Sharath kumar R

  • Is there a way to view all the table names in a certain schema?

    Is there a way to view all the table names in a certain schema?

    SELECT table_name FROM user_tablesThat won't do much good given this piece of information:
    i am trying to finish a lab for school but i don't know what tables are in my
    professor's schema. The appropriate solution is
    SELECT table_name
    FROM all_tables
    WHERE owner = 'PROFESSOR_YAFFLE'
    /This will show the names of the tables which Prof. Yaffle has granted to us.
    Cheers, APC

  • How can I make all the Tables in my spreadsheet to work as one?

    I made a spreadsheet for work in Numbers '09 but do to the computers that we have at work, I have to have it exported to Windows Excel, but when I try to export the spreadsheet since I used more than 1 table to create this spreadsheet, each table is converted to an Excel worksheet, and all other objects are placed on separate worksheets since there's more than one table. and I want to know is there anything I can do, to export everything in one spreadsheet, for all the tables to work as one spreadsheet. PLEASE HELP!!

    You may be able to easily consolidate all your tables into one big table to make it equivalent to an Excel worksheet. You can copy/paste from one table to another and you can drag columns or rows from one table and insert them into another. Note that formulas that use column letters or row numbers instead of specific ranges (i.e., B instead of B2:B10) will now refer to the entire column/row in the destination table.
    Without doing this, all the tables, when exported to Excel into separate worksheets, should still work together just like they did in Numbers. Are you saying that they do not?
    Not much you can do about objects.

  • How to find all the tables associated for a particular transaction

    Hi-
    May I know how to find all the tables, related(foreign key) tables for a transaction within SAP GUI?
    Up to my technical knowledge, this can be achieved by looking database diagrams from DB level. But that would be for entire database as a whole. What I'm expecting is to see transaction level relative tables that too from SAP GUI. Please share the possibilities if any.
    Regards
    Sekhar

    Dear Micky Oestreich
    May be we possess expertise or high level experience, it should not show up in our way of communication. Every professional starts with the basic stuff to learn. When the question is raised in such minimum polite way, the same level of courtesy is expected in return. If you felt my question was basic, you might have refused it gently. If you are in good mood or bad mood it doesn't matters.
    Hi Vengal Rao
    Thanks for your response. It helped me.
    Regards
    Sekhar

  • How to find all the table used in a report

    Hi Expert ,
                    Is there is any program  to find out all the tables which  are used in a perticular report .
    Thanks in advance
    Tarak

    Well, so far Viquar Iqbal has given the only really correct answer - use SQL trace.  The reason the others are incomplete, is because they don't consider that a report might call a function module or a class method that accesses a table.  In fact, for many applications this is exactly what happens - db accesses are abstracted away from the main program.
    The other alternative to SQL trace is to use Run Time Analysis.  The advantage of SQL trace is that it shows the tables hit in order.
    matt

  • How will get the source code of all the tables in a given schema using SQL?

    Hi All,
    How can we get the source code of all the tables in a given schema using SQL?
    Thanks in Adv.
    Junu

    Try something like...
    set heading off
    set pagesize 0
    col meta_data for a96 word_wrapped
    set long 100000
    SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner) ||';' AS meta_data
    FROM dba_objects
    WHERE owner = '<SCHEMA NAME>'
      AND object_type not in (<list of stuff you do not want>);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • How to Use Mobile Service in HTML/JavaScript Application

    The Windows Azure Mobile Service is a back end tool for mobile applications. It supports various platforms, such as Windows Store, Windows Phone 8, iOS and Android. The Windows Azure Mobile service can also support HTML/JavaScript. This article helps

  • Standard Preview Size/Preview Quality

    This may be a silly question, but in Library mode, under Edit>Catalogue Settings>File Handling, you have options under Preview Cache for 'Standard Preview Size' (1024/1440/1680/2048/2880 pixels) and Preview Quality (High/Medium/Low)... but what do th

  • ORACLE.FDK.FEATURENOTENABLED error in Oracle Web Services

    I downloaded Oracle Web Services (10.1.2) sample code from the link - http://www.oracle.com/technology/products/cs/developer/contentservicesdev/contenservicesdevkit.html to upload documents into OCS. I modified the properties file (ws.properties) and

  • Problem Updating CS6

    I gen an error when I try to upload CS6 - using OS X 10.8.4 DPS Desktop Tools CS6 27.0.0 Update Installation Successful. Error Code: U44M1I0 Adobe Bridge CS6 5.0.2 Update Installation Successful. Error Code: U44M1I0 Photoshop Camera Raw 8.1(CS6) Inst

  • CRLF issue

    Hi, We are gearing up for our integration testing with our 30 odd EDI partners. But we have a small subset who are using Carriage Return Line feed hexa decimal values ( 0D 0A) as delimiters in our inbound documents which might potentially cause our B