|
-
You need to use dynamic sql to pass table_name.
Example:
CREATE OR REPLACE procedure tamil_upd_sbl_tbls_rowcount as
p_rowcount Number := 0 ;
p_tablesize Number := 0 ;
stmt_str varchar2(4000) ;
p_new_run_id Number := 0 ;
p_tsname varchar2(30);
p_ext Number := 0 ;
begin
---- execute immediate 'truncate table tamil_dba_siebel_tables';
---- get maximum run_id from tamil_dba_siebel_tables
execute immediate
'alter session set optimizer_mode = choose ' ;
select max(run_id) into p_new_run_id
from tamil_dba_siebel_tables;
p_new_run_id := nvl(p_new_run_id,0) + 1; ---- increment by 1
for ctab in ( select table_name as tabname
from user_tables
) Loop
-- dbms_output.put_line(ctab.tabname||' '|| ctab.tabname) ;
stmt_str := 'select /*+ full(a) parallel(a,8) */ count(*) from '||ctab.tabname ||' a';
-- dbms_output.put_line(stmt_str);
execute immediate stmt_str into p_rowcount ;
stmt_str := 'select bytes , tablespace_name, extents from user_segments where '
||'segment_name = :X1 ' ;
execute immediate stmt_str into p_tablesize, p_tsname, p_ext using ctab.tabname ;
---- first, insert tables' details
insert into tamil_dba_siebel_tables
(run_id, object_name, object_type, row_count, bytes, run_date, tablespace_name, extents)
values
(p_new_run_id, ctab.tabname, 'TABLE', p_rowcount, p_tablesize, sysdate, p_tsname, p_ext);
end loop ;
---- next, insert indexes' details
insert into tamil_dba_siebel_tables
(run_id, object_name, object_type, row_count, bytes, run_date, tablespace_name, extents)
select p_new_run_id, segment_name, 'INDEX', 0, bytes, sysdate, tablespace_name, extents
from user_segments
where segment_type = 'INDEX' ;
commit;
exception when others then
dbms_output.put_line('Error encounterd ' );
end;
/
The above procedure does row counts and store in a table.
Tamil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|