IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Query regarding Cursors in PL/SQL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rashmi jayakrishnan

New User


Joined: 28 Mar 2008
Posts: 3
Location: mysore

PostPosted: Sat Apr 05, 2008 8:04 am
Reply with quote

HI all

i have query regrading PL/SQL cursors

See the below examples


DECALRE CURSOR CUR_NEW IS
SELECT F_NAME from TBL_EMP WHERE AGE = 20;

for updating last name of those specific records ,we should give the same where condition in UPDATE command also. this is what i am thinking. please tell me whether i am right.

otherwise we can code like this

DECALRE CURSOR CUR_NEW IS
SELECT F_NAME form TBL_EMP WHERE AGE = 20
FOR UPDATE OF LAST_NAME;


and

UPDATE TBL_EMP SET LAST_NAME='kanjan'
when CURRENT OF CUJR_NEW


also tell me in the first approach if we havnt given the slection criteria that we used for UPDATE , what will happen?
whether it will point only the records selected in the cursor?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Apr 05, 2008 9:20 am
Reply with quote

Hello,

Is there some reason to use a cursor?

Why select f_name? It does not appear to be used icon_confused.gif

Would a simple "update" ... "where age=20 do what you want?

There may be something that i do not understand correctly. . .
Back to top
View user's profile Send private message
gvsus

New User


Joined: 27 Mar 2008
Posts: 4
Location: USA

PostPosted: Sat Apr 05, 2008 6:24 pm
Reply with quote

Why would you want to update all records with AGE = 20 to same LAST_NAME?

If thats what you really want to do, then you don't require a CURSOR, just use the Update.

Code:
UPDATE TBL_EMP SET LAST_NAME='kanjan' WHERE AGE = 20;


It will update all rows that have AGE = 20 with the LAST_NAME you specified.

If you want to use CURSOR for UPDATE, you still need to DECLARE, OPEN, FETCH that cursor before you can UPDATE any row. Once you FETCH a row then you can decide if you want to UPDATE that record or skip it and FETCH the next record.
But it is best to have the SELECTION criteria in the WHERE clause of the SELECT, so that you might not be locking up the rows that are not really needed for update.

Thanks
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top