Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what is cursor into sql server and what is the use of cursor into our querry ?

UPDATE: from comments:


+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
+----+----------+-----+-----------+----------+


SQL
DECLARE 
total_rows number(2);
BEGIN
  UPDATE customers
  SET salary = salary + 500;
  IF sql%notfound THEN
    dbms_output.put_line('no customers selected');
  ELSIF sql%found THEN
    total_rows := sql%rowcount;
    dbms_output.put_line( total_rows || ' customers selected ');
  END IF; 
END;



table data and query is given above but i dont understand the use of cursor and the purpose of using cursor here please see this and explain this into simple words i am very new to cursor .

thanks
/
Posted
Updated 5-Nov-15 23:52pm
v2

1 solution

It's a loop that executes for each row of the select. This is useful if you need to perform complex functions that cannot be run on a dataset.

As for how it is used in your query? I don't know. I can neither see your monitor nor read your mind. Sorry for my lack of ability :P

Hope that helps ^_^
Andy

UPDATE:
Ah, Oracle. You didn't tell me that >_<

This is not a cursor. In this case it is just a single update statement then throws an output to the entity framework letting you know if the customer was found or not

This link happens to talk about the return message AND cursors:

http://stackoverflow.com/questions/13075538/pl-sql-notfound[^]
 
Share this answer
 
v2
Comments
Andy Lanng 6-Nov-15 5:58am    
Try to use the "Improve Question" button when adding code. Formatting is often lost in the comments.

I have added it for you and added the code tags. I have also updated my solution in response.

Please accept my solutuion if it answers your question ^_^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900