Home » SQL & PL/SQL » SQL & PL/SQL » cursor and loop (oracle10g)
cursor and loop [message #634356] Mon, 09 March 2015 02:12 Go to next message
asifkhan1990.cse
Messages: 11
Registered: February 2015
Location: INDIA
Junior Member

Dear all,

can we use loop instead of cursor in plsql block if need.

Help please.


advance thanks.

Re: cursor and loop [message #634357 is a reply to message #634356] Mon, 09 March 2015 02:17 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Well, cursors usually are used when you want to do something in a loop (i.e. process certain information one-by-one. Some people here emphasize that this "row-by-row" processing is "slow-by-slow", but sometimes you can't avoid it).

So, what exactly do you mean "a loop INSTEAD OF a cursor"? If you could explain a problem you are trying to solve, someone might suggest how you should do it.
Re: cursor and loop [message #634358 is a reply to message #634356] Mon, 09 March 2015 02:18 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Please read and follow the OraFAQ Forum Guide and How to use [code] tags, to enable us to help you.

asifkhan1990.cse wrote on Mon, 09 March 2015 12:42

can we use loop instead of cursor in plsql block if need.



It is not clear what you are asking. Are you talking about a CURSOR FOR LOOP?

Something like,

BEGIN
  FOR i IN
  (SELECT * FROM emp
  )
  LOOP
    ...
  END LOOP;
END;
/ 


[Updated on: Mon, 09 March 2015 02:19]

Report message to a moderator

Re: cursor and loop [message #634363 is a reply to message #634358] Mon, 09 March 2015 02:30 Go to previous messageGo to next message
asifkhan1990.cse
Messages: 11
Registered: February 2015
Location: INDIA
Junior Member

i mean is it possible to update record by loop one by one or delete record...if so..then
why do we need cursor..
Re: cursor and loop [message #634364 is a reply to message #634363] Mon, 09 March 2015 02:33 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It is possible, if you know which record you are updating or deleting. Why would you need a cursor for that? Why do you need a loop for that? UPDATE (or DELETE) is just enough.
Re: cursor and loop [message #634372 is a reply to message #634356] Mon, 09 March 2015 02:43 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

http://www.orafaq.com/forum/mv/msg/196587/633956/#msg_633956

Re: cursor and loop [message #634552 is a reply to message #634372] Wed, 11 March 2015 05:16 Go to previous messageGo to next message
msol25
Messages: 396
Registered: June 2011
Senior Member
Dear Asif,

Please read the concept for Implicit and explicit cursor.

When calling Cursor explicitly in pl/sql,then we call it explicit cursor.If running normal sql query, then Implict cursor comes into picture.



We process the data in explicit cursor,Only in the case which is not possible through sql query.
Re: cursor and loop [message #634554 is a reply to message #634552] Wed, 11 March 2015 05:19 Go to previous message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You always have the choice to use the one you want. There is no difference between the two only the way you program.

Previous Topic: Complex comparision query
Next Topic: String Compress
Goto Forum:
  


Current Time: Tue Apr 23 10:44:06 CDT 2024