求救!!!有关存储过程....

土星人在海边 2003-04-09 03:54:04
在存储过程中如何实现一下功能:
1。查询表A中符合条件的结果n条
2。对每一条记录进行操作
需要实现例如 i:=1 to n do
begin
......
query.next;//这个怎么实现??
end;
谢谢 谢谢
...全文
42 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
土星人在海边 2003-04-09
  • 打赏
  • 举报
回复
thanks
newdongkui 2003-04-09
  • 打赏
  • 举报
回复
你非要这样的话有游标吧
USE pubs
GO

-- Declare the variables to store the values returned by FETCH.
DECLARE @au_lname varchar(40), @au_fname varchar(20)


DECLARE authors_cursor CURSOR FOR
SELECT au_lname, au_fname FROM authors
WHERE au_lname LIKE "B%"
ORDER BY au_lname, au_fname

OPEN authors_cursor

-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.

FETCH NEXT FROM authors_cursor
INTO @au_lname, @au_fname

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN

-- Concatenate and display the current values in the variables.
PRINT "Author: " + @au_fname + " " + @au_lname

-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM authors_cursor
INTO @au_lname, @au_fname
END

CLOSE authors_cursor
DEALLOCATE authors_cursor
GO

pengdali 2003-04-09
  • 打赏
  • 举报
回复
use pubs----------选择
go

declare dali_cursor scroll cursor for------------定义游标
select * from jobs where max_lvl>100 ----------游标体查找语句
open dali_cursor-----------------打开游标



-------fetch next from dali_cursor------------提取游标-----next---last




close dali_cursor------------------关闭游标
deallocate dali_cursor------------释放游标
pengdali 2003-04-09
  • 打赏
  • 举报
回复
declare cursor_insert cursor for select c# from cs
declare
@i int
open cursor_insert
fetch cursor_insert into @i
while @@fetch_status=0
begin
print @i
fetch cursor_insert into @i
end
close cursor_insert
deallocate cursor_insert

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧