| |

VerySource

 Forgot password?
 Register
Search
View: 793|Reply: 7

SQL SERVER updatable cursor problem ~~~ `

[Copy link]

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-29 23:30:01
| Show all posts |Read mode
A simple example, I want to test it, but I can't seem to update the email. I don't know what the problem is?
declare my_cur CURSOR for select email from tbl_user
     open my_cur
     while @@ fetch_status = 0
     begin
        update tbl_user set email = 'test' where current of my_cur
        fetch next from my_cur
     end
Reply

Use magic Report

0

Threads

26

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-5-25 17:00:02
| Show all posts
There is no problem in grammar
Reply

Use magic Report

0

Threads

21

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-27 05:30:01
| Show all posts
open my_cur
Add the following

fetch next from my_cur
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-5-27 15:30:03
| Show all posts
DECLARE My_Cur CURSOR SCROLL DYNAMIC
FOR
SELECT Email FROM MyUser
OPEN My_Cur
FETCH next FROM My_Cur
WHILE (@@ FETCH_STATUS = 0)
BEGIN
  UPDATE MyUser SET Email = 'Just For Test' WHERE CURRENT OF My_Cur
  FETCH next FROM My_Cur
END
DEALLOCATE My_Cur
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-5-27 17:15:01
| Show all posts
When the cursor is opened, the cursor is automatically positioned on the first record in the record set.

Without fetch next from my_cur
Reply

Use magic Report

0

Threads

21

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-28 12:15:01
| Show all posts
Facts speak louder than words

You know it as soon as you try
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-28 21:45:01
| Show all posts
DECLARE My_Cur CURSOR SCROLL DYNAMIC
FOR
SELECT Email FROM MyUser
OPEN My_Cur
FETCH next FROM My_Cur
WHILE (@@ FETCH_STATUS = 0)
BEGIN
  UPDATE MyUser SET Email = 'Just For Test' WHERE CURRENT OF My_Cur
  FETCH next FROM My_Cur
END
DEALLOCATE My_Cur
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-2 07:30:02
| Show all posts
Updatable cursor plus for update
declare my_cur CURSOR for select email from tbl_user for update
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list