473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

run dbms_stats for a set of tables through a PL/SQL block

Hi Guys,

I am trying to run dbms_stats for a set of tables through a PL/SQL block and want to incorporate this in a shell script to automate it.

I am using execuute immediate, but I am getting the following error when I run this block:

DECLARE
v_stats varchar2(1000);
cursor st_cursor is
select owner, table_name from dba_tables where owner='XYZ' and table_name in(
'XX,
YY,
'ZZ',
'ZZ1',
'ZZ2');
BEGIN
for st_row in st_cursor loop
v_stats := 'execute dbms_stats.gather_table_stats(ownname=>'||''''||st _row.owner||''''||','||'tabname=>'||''''||st_row.t a
ble_name||''''||','||'estimate_percent=>1'||','||' method_opt=>'||''''||'FOR ALL INDEXED COLUMNS SIZE SKEWONLY'||''''||','||'
degree=> 6'||','||'granularity=>'||''''||'GLOBAL'||''''||', '||'cascade=>false);';
execute immediate v_stats;
end loop;
END;
/

ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 13

I will be running gather_index_stats in a separate cursor within this block, but want this to work. Any help would be appreciated
May 21 '07 #1
3 10985
MMcCarthy
14,534 Expert Mod 8TB
I moved this question to it's own thread. You are more likely to receive assistance this way.

ADMIN
May 21 '07 #2
Saii
145 Expert 100+
when calling a proc/function in PL/SQL block, we dont need to use "execute proc", directly call it.
May 21 '07 #3
chandu031
78 Expert
Hi Guys,

I am trying to run dbms_stats for a set of tables through a PL/SQL block and want to incorporate this in a shell script to automate it.

I am using execuute immediate, but I am getting the following error when I run this block:

DECLARE
v_stats varchar2(1000);
cursor st_cursor is
select owner, table_name from dba_tables where owner='XYZ' and table_name in(
'XX',
'YY',
'ZZ',
'ZZ1',
'ZZ2');
BEGIN
for st_row in st_cursor loop
v_stats := 'execute dbms_stats.gather_table_stats(ownname=>'||''''||st _row.owner||''''||','||'tabname=>'||''''||st_row.t a
ble_name||''''||','||'estimate_percent=>1'||','||' method_opt=>'||''''||'FOR ALL INDEXED COLUMNS SIZE SKEWONLY'||''''||','||'
degree=> 6'||','||'granularity=>'||''''||'GLOBAL'||''''||', '||'cascade=>false);';
execute immediate v_stats;
end loop;
END;
/

ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 13

I will be running gather_index_stats in a separate cursor within this block, but want this to work. Any help would be appreciated
Hi ,
Try this out:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DECLARE 
  3. v_stats varchar2(1000); 
  4.  
  5. BEGIN 
  6.  
  7. for st_row in (select owner, table_name from all_tables where owner='XYZ and table_name in( 
  8. 'XX, 
  9.   YY, 
  10.   'ZZ', 
  11.   'ZZ1', 
  12.   'ZZ2')
  13. )
  14. loop
  15.  
  16. v_stats := 'begin dbms_stats.gather_table_stats(ownname=>'||''''||st_row.owner||''''||','||'tabname=>'||''''||
  17. st_row.table_name||''''||','||'estimate_percent=>1'||','||'method_opt=>'||''''||'FOR ALL INDEXED COLUMNS SIZE SKEWONLY'||''''||','||' 
  18. degree=> 6'||','||'granularity=>'||''''||'GLOBAL'||''''||','||'cascade=>false); end;'; 
  19. execute immediate v_stats; 
  20. end loop; 
  21.  
  22. end; 
  23.  
Hope this helps!
May 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joseph Ferris | last post by:
Hello, I am having an issue with page breaking that I hope someone will be able to help me with. Still a relative "newbie", and I thought this might be a good place to find some help. I have a...
5
by: Robert J. O'Hara | last post by:
For some time I've made use of the max-width property in CSS to cause my pages to appear as a centered block against a contrasting background. This works well in new browsers (Mozilla, etc.) and...
5
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the...
11
by: Mark Schneider | last post by:
I'm trying to avoid using <table> for formatting purposes where other, reasonable means exist. I'm stuck trying to find a way to find an equivalent for the code below. <table align="center">...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
53
by: Alan Silver | last post by:
Hello, I understand the issue that tables should be used for tabular data and not for layout, but I would like some clarification as to exactly what constitutes tabular data. For example, if...
4
by: axlq | last post by:
Suppose I had to lay out a part of a page where I wanted to retain the horizontal and vertical relationship of the elements. Yes, this is what tables are for. I was curious if it can be done in...
5
by: Markus Ernst | last post by:
Hello This is a test example: http://www.markusernst.ch/anthracite/ http://www.markusernst.ch/anthracite/living_divani.html After googling and experimenting for several hours, I ended up...
7
by: Gary | last post by:
Hello guys! Bear with me, I am a newbie. She is the Data Warehouse manager. She has about 50 users to use the Oracle database from M$ Access via ODBC connection. All those users have only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.