sql server 动态游标
declare @sql varchar(2000),
@typefield varchar(100),
@tablename varchar(255),
@name varchar(100)
select @typefield = 'name',@tablename = 'sysobjects'
set @sql = ' declare cuTemp cursor for '
+' SELECT DISTINCT '+@typefield + ' FROM ' + @tablename
exec (@sql)
open cuTemp
fetch cuTemp into @name
while (@@fetch_status=0)
begin
print @name
fetch cuTemp into @name
end
close cuTemp
DEALLOCATE cuTemp
pl/sql动态游标
create or replace procedure activecursor(tn varchar2) as
a1 number(10) := 0;
sql_statement varchar2(1000);
type curtype is ref cursor;
cur_jilh curtype;
begin
savepoint ticketcount;
sql_statement := 'select aa,bb from ' || tn;
open cur_jilh for sql_statement;
loop
fetch cur_jilh
into sql_statement,a1;
exit when cur_jilh%notfound;
end loop;
close cur_jilh;
commit;
EXCEPTION
WHEN OTHERS THEN
rollback to ticketcount;
end activecursor;