The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sqlplus call JohnZ1385 UNIX for Dummies Questions & Answers 1 06-05-2008 07:48 AM
Sqlplus LiquidChild Shell Programming and Scripting 9 06-01-2007 08:22 AM
SQLPLUS in script renichols Shell Programming and Scripting 4 03-06-2006 08:43 AM
sqlplus invocation new2ss Shell Programming and Scripting 4 02-07-2006 12:41 AM
returning value from sqlplus malaymaru Shell Programming and Scripting 1 01-31-2006 12:03 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-12-2006
Registered User
 

Join Date: Apr 2006
Posts: 4
Sqlplus

Hi all,
I am new to SQLPLUS, can anyone tell me what is the following codes doing?

DECLARE
cursor c1 is select bts_int_id,
max(ave_busy_tch/res_av_denom14) maxBusyTch
from p_nbsc_res_avail
where to_char(period_start_time,'yyyymmdd')=to_char((sysdate-1),'yyyymmdd')
group by bts_int_id;
BEGIN
FOR x IN c1 LOOP
update RNP_temp_table set
bts_id = x.bts_int_id,
max_busy_tch=x.maxBusyTch
where bts_id = x.bts_int_id;

IF SQL%NOTFOUND THEN
insert into RNP_temp_table
( bts_id,
max_busy_tch)
values
( x.bts_int_id,
x.maxBusyTch);
END IF;
COMMIT;
END LOOP;

COMMIT;
END;
/
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-12-2006
Registered User
 

Join Date: Jul 2006
Posts: 19
Hi friend,

This is a procedure which open a cursor, using select statement from p_nbsc_res_availTable where users fetch data where Period_start_time is equal to previous date.
Then using this cursor a loop update records in RNP_temp_table Table. if it found in cursor aotherwise that record inserted. Then it commit your changes. But i think you should remove first commit that is inside loop your next commit commit will fix all chages at the end of the procedure.

Thanks.
Reply With Quote
  #3 (permalink)  
Old 09-12-2006
Registered User
 

Join Date: Apr 2006
Posts: 4
Thanks for your reply. Now I have a better picture on how this things work. Between, is cursor must be declare every time like in the script?

declare cursor c1 is select .......

and also what if i remove the both commit command, will the script give me same result?

and is it for...loop, if...then can only be written after begin command?


Thanks again for your generous help!


Anthony Kiu
Reply With Quote
  #4 (permalink)  
Old 09-13-2006
Registered User
 

Join Date: Jul 2006
Posts: 19
Hi,
see cursor only require when you have to traverse in between the records fetched from Table using select command. yeaa obviously cursor only be defined using select command only because it is something like a pointer in memry location where jump on evry row. yeaa it is a common practice to open a cursor to run a loop.

see commit will be used to fix your changes. you can commt later also it does n't have an business with your procedure and loop, but it certainly ensure security.

Thanks
Mukund Ranjan.
Reply With Quote
  #5 (permalink)  
Old 09-13-2006
Registered User
 

Join Date: Apr 2006
Posts: 4
Hi friend,

Thanks a lot for you help. It helps me to understand more about sqlplus.



Anthony
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0