方法一:
CREATE TABLE #tabTmp(id int)
INSERT #tabTmp EXECUTE('SELECT id FROM '+@TableName)
declare curOne cursor for
SELECT id FROM #tabTmp
open curOne
FETCH NEXT from curOne into @ID
INSERT #tabTmp EXECUTE('SELECT id FROM '+@TableName)
declare curOne cursor for
SELECT id FROM #tabTmp
open curOne
FETCH NEXT from curOne into @ID
方法二:
exec('
declare curOne cursor global
for' + @aSql);
declare @str nvarchar(20);
open curOne
fetch curOne into @str;
while(@@fetch_status=0)
begin
...
fetch curOne into @str;
end;
close curone;
deallocate curone;
declare curOne cursor global
for' + @aSql);
declare @str nvarchar(20);
open curOne
fetch curOne into @str;
while(@@fetch_status=0)
begin
...
fetch curOne into @str;
end;
close curone;
deallocate curone;
相比之下ORACLE用起来真是直观很多
CURSOR c_get_f_name
(
id INT
)
IS
SELECT F_ID, F_NAME
FROM F_INFO
WHERE (F_ID IN(
SELECT F_ID
FROM A_DOT
WHERE (A_ID = id)));