-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_details.sql
65 lines (53 loc) · 1.79 KB
/
table_details.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
pl/sql Script to list the space occupied by a given table and it's indexes and other details.
*/
declare
l_owner dba_tables.owner%type := 'SCOTT';
l_table_name dba_tables.table_name%type := 'EMP';
l_table_size dba_segments.bytes%type;
l_partitioned dba_tables.partitioned%type;
l_index_size dba_segments.bytes%type;
begin
dbms_output.put_line(rpad('Table:',50,' ') || l_owner || '.' || l_table_name);
--check if table is partitioned or not.
select partitioned
into l_partitioned
from dba_tables
where owner = l_owner
and table_name = l_table_name;
dbms_output.put_line(rpad('Partitioned?:',50,' ') || l_partitioned);
-- Table Size
select sum(bytes)
into l_table_size
from dba_segments
where owner = l_owner
and segment_name = l_table_name;
dbms_output.put_line('');
dbms_output.put_line(rpad('Table Size:',50,' ') || trunc(l_table_size/1024/1024/1024,2) || ' GB');
dbms_output.put_line('');
dbms_output.put_line('Index details:');
dbms_output.put_line('--------------');
-- are indexes partitioned? (to see if there are any global indexes)
for v_rec in (
select index_name,
case when partitioned = 'YES' then 'local' else 'global' end index_type
from dba_indexes
where owner = l_owner
and table_name = l_table_name
) loop
dbms_output.put_line(rpad('INDEX: ' || v_rec.index_name, '50') || v_rec.index_type);
end loop;
dbms_output.put_line('');
-- index size
select trunc(sum(bytes)/1024/1024/1024,2)
into l_index_size
from dba_segments
where (owner, segment_name) in (
select owner, index_name
from dba_indexes
where owner = l_owner
and table_name = l_table_name
);
dbms_output.put_line(rpad('INDEX Size: ',50) || l_index_size || ' GB');
end;
/