日期:2014-05-17 浏览次数:20497 次
CREATE PROCEDURE p_orderinfo
@age int,
@orderitem_cursor CURSOR VARYING OUTPUT
AS
DECLARE @sql VARCHAR(1000)
SET @sql='SET @orderitem_cursor = CURSOR FOR SELECT name FROM student WHERE age>'+CONVERT(VARCHAR,@age)+' ;';
EXEC(@sql);
--SET @orderitem_cursor = CURSOR FOR SELECT name FROM v_orderitem;
OPEN @orderitem_cursor;
GO
DROP PROCEDURE p_orderinfo;
--测试
DECLARE
@orderitem_cursor CURSOR,
@name VARCHAR(20)
BEGIN
EXEC p_orderinfo 22,@orderitem_cursor OUTPUT;
FETCH NEXT FROM @orderitem_cursor INTO @name;
WHILE @@FETCH_STATUS=0
BEGIN
SELECT @name;
FETCH NEXT FROM @orderitem_cursor INTO @name;
END;
CLOSE @orderitem_cursor;
DEALLOCATE @orderitem_cursor;
END;
CREATE PROCEDURE p_orderinfo
@age int,
@orderitem_cursor CURSOR VARYING OUTPUT
AS
DECLARE @sql NVARCHAR(1000)
declare @parmsDefine nvarchar(500)
set @parmsDefine=N'@_cursor CURSOR'
SET @sql=N'SET @_cursor = CURSOR FOR SELECT name FROM student WHERE age>'+CONVERT(VARCHAR,@age)+' ;';
EXEC sp_executesql @sql,@parmsDefine,@_cursor=@orderitem_cursor;
--SET @orderitem_cursor = CURSOR FOR SELECT name FROM v_orderitem;
OPEN @orderitem_cursor;
GO
DROP PROCEDURE p_orderinfo;
--测试
DECLARE
@orderitem_cursor CURSOR,
@name VARCHAR(20)
EXEC p_orderinfo 22,@orderitem_cursor OUTPUT;
FETCH NEXT FROM @orderitem_cursor INTO @name;
WHILE @@FETCH_STATUS=0
BEGIN
SELECT @name;
FETCH NEXT FROM @orderitem_cursor INTO @name;
END;
CLOSE @orderitem_cursor;
DEALLOCATE @orderitem_cursor;