Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 25th, 2008, 02:49 PM
Nallagangu Nallagangu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 22 Nallagangu New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 5 h 6 m 16 sec
Reputation Power: 0
The bigger problem... tunning!!

Hi everyone...
Actually i dont know how to tune a procedure... i am giving u all the data if u can please help me....

Function:
create or replace
function dump_data( p_query in varchar2,
p_dir in varchar2 ,
p_filename in varchar2 )
return number
is
l_output utl_file.file_type;
l_theCursor integer default dbms_sql.open_cursor;
l_columnValue varchar2(2000);
l_status integer;
l_colCnt number default 0;
l_separator varchar2(10) default '';
l_cnt number default 0;
begin
l_output := utl_file.fopen( p_dir, p_filename, 'w' );

dbms_sql.parse( l_theCursor, p_query,
dbms_sql.native );

for i in 1 .. 255 loop
begin
dbms_sql.define_column( l_theCursor, i,
l_columnValue, 2000 );
l_colCnt := i;
exception
when others then
if ( sqlcode = -1007 ) then exit;
else
raise;
end if;
end;
end loop;

dbms_sql.define_column( l_theCursor, 1,
l_columnValue, 2000 );

l_status := dbms_sql.execute(l_theCursor);

loop
exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
l_separator := '';
for i in 1 .. l_colCnt loop
dbms_sql.column_value( l_theCursor, i,
l_columnValue );
utl_file.put( l_output,
l_separator || l_columnValue );

end loop;
utl_file.new_line( l_output );
l_cnt := l_cnt+1;
end loop;
dbms_sql.close_cursor(l_theCursor);

utl_file.fclose( l_output );
return l_cnt;
end dump_data;

Procedure

create or replace
procedure MEXICO_NAFTA_CERTIFICATE_EXT as

l_rows number;
begin
l_rows := dump_data( 'select c1.certificate_nbr, c2.part_nbr as part171, c2.inactive_ind,
c2.hts_cde, c2.originating_ind, c3.iso_country_cde, c2.basis_cde, c2.producer_cde, c2.cert_cde,
c2.regional_value_content_cde, c2.part_nbr, c1.effective_dte
from certificates c1 , certificate_parts c2 ,displayed_countries_of_origin c3 where c1.certificate_nbr=c2.certificate_nbr and c2.certificate_nbr=c3.certificate_nbr',
',' '/d014/oradata/temp',
'MEXICO_NAFTA_CERTIFICATE_EXT.txt' );
dbms_output.put_line( to_char(l_rows) ||
' rows extracted to ascii file' );
end;

Both the function and procedures got executed without errors but its taking really long time to get output... it have to load almost 99842 rows in the text file...

i have to tune that query and i really dont know how to...

explain plan of the query:
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1014373765

--------------------------------------------------------------------------------
-----------------------------

| Id | Operation | Name | Rows | Bytes |Tem
pSpc| Cost (%CPU)| Time |

--------------------------------------------------------------------------------
-----------------------------


PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 18M| 813M|
| 7318 (3)| 00:01:43 |

|* 1 | HASH JOIN | | 18M| 813M|
16M| 7318 (3)| 00:01:43 |

| 2 | TABLE ACCESS FULL | DISPLAYED_COUNTRIES_OF_ORIGIN | 884K| 6047K|
| 394 (4)| 00:00:06 |

|* 3 | HASH JOIN | | 733K| 27M| 2
352K| 4554 (1)| 00:01:04 |

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------

| 4 | TABLE ACCESS FULL| CERTIFICATES | 99841 | 1170K|
| 657 (1)| 00:00:10 |

| 5 | TABLE ACCESS FULL| CERTIFICATE_PARTS | 733K| 19M|
| 2592 (2)| 00:00:37 |

--------------------------------------------------------------------------------
-----------------------------



PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

1 - access("C2"."CERTIFICATE_NBR"="C3"."CERTIFICATE_NBR")
3 - access("C1"."CERTIFICATE_NBR"="C2"."CERTIFICATE_NBR")

18 rows selected.

it should be 99848 rows selected not 18 and i dont know why....

i am really not understaing... please some one help me....

Thanking You

Bhagya

Reply With Quote
  #2  
Old April 25th, 2008, 03:28 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 5 h 6 m 18 sec
Reputation Power: 259
Would you mind reading this ?

Reply With Quote
  #3  
Old April 25th, 2008, 03:40 PM
Nallagangu Nallagangu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 22 Nallagangu New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 5 h 6 m 16 sec
Reputation Power: 0
I read it.... and i understood it.... i have just started as an developer and i am really unable to figure out... i already had my first warning yesturday form my DB saying that my processes have hang up the database.... thats why i need some help.... plese help me if u can.....day by day i am getting near to losing my job...

Reply With Quote
  #4  
Old April 25th, 2008, 04:48 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 5 h 6 m 18 sec
Reputation Power: 259
Quote:
Originally Posted by Nallagangu
I read it.... and i understood it....
I don't think so, read it again
Quote:
1. use a descriptive subject for your posts
2. include full error messages and table(s) structure
3. add proper formatting to your code, make it easy to read
4. describe your requirements and expected results
5. provide sample data to reproduce your case
6. post the solution if you got it elsewhere
some of these points apply to this thread too

Reply With Quote
  #5  
Old April 25th, 2008, 05:04 PM
Nallagangu Nallagangu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 22 Nallagangu New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 5 h 6 m 16 sec
Reputation Power: 0
Ok.... The actual task is to get few columns(12) form 3 tables and extract them to a text file....i have tried and used the concept of UTIL File.... the above code is about it.... but i dint work properly.... can u help me now...

bhagya
Comments on this post
pabloj disagrees: Don't try to skip steps

Reply With Quote
  #6  
Old April 25th, 2008, 05:10 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 5 h 6 m 18 sec
Reputation Power: 259
Quote:
Originally Posted by Nallagangu
... can u help me now...

bhagya
No, you are still deliberately ignoring a few points, some of which are not only "cosmetic" but actually very important for query optimization, here they are
Quote:
1. use a descriptive subject for your posts
2. include full error messages and table(s) structure
3. add proper formatting to your code, make it easy to read

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > The bigger problem... tunning!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway