文章已阅读
 

@@fetch_status= 0 fetch语句执行成功
@@fetch_status=-1 fetch语句失败或行不在结果集中
@@fetch_status=-2 提取的行不存在
@@fetch_status=-9 光标未执行提取操作

@@error=0 表示执行出错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
*/
create procedure p_test
as
begin
begin tran
declare cur_test cursor for
select id, name,dates from test where 1=1
declare @id int, @name varchar(50),@dates datetime
open cur_test
fetch next from cur_test into @id,@name,@dates
while @@fetch_status<>-1
begin
update test set name='x' where id=@id
if @@error<>0
begin
rollback tran
end
select *from test where id=@id
if @@error<>0
begin
rollback tran
end
fetch next from cur_test into @id,@name,@dates
end
close cur_test
deallocate cur_test
commit tran
end
--sp_helptext p_test

alter procedure p_test1
as
begin
begin tran
declare cur_sa cursor for
select id,name,thing,dates from test
declare @id int,@name varchar(50),@thing varchar(50),@dates varchar(50)
open cur_sa
fetch next from cur_sa into @id,@name,@thing,@dates
while @@fetch_status<>-1
begin
select *from test where id=@id
if @@error<>0
begin
rollback tran
end

fetch next from cur_sa into @id,@name,@thing,@dates
end
close cur_sa
deallocate cur_sa
commit tran
end
2023-04-02

浏览 |

© 2023 南疆 with help from Hexo and Twitter Bootstrap. Theme by Freemind.

container-narrow -->