Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query regarding Cursors in PL/SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Query regarding Cursors in PL/SQL
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

Site Director


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

PostPosted: Sat Apr 05, 2008 9:20 am    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us