Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 reg query on DYNALLOC feature raghuraman123 SYNCSORT 12 Wed Jan 10, 2018 2:42 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us