--游标遍历某个字段 (打印出来) declare res_sql varchar2(2000); cursor cur is select f_dcname from W_EC_PLACESTATION_COLLECT t where f_collectdate >= TRUNC(TO_DATE('2018-09-01','yyyy-MM-dd'),'month') AND f_collectdate < TO_DATE('2…
sql server游标: --定义游标 declare cursor1 cursor for select ID,Name from A --打开游标 open cursor1 declare @id int declare @name varchar(50) declare @n int declare @i int=1 set @n=(select COUNT(1) from A) while(@i<@n) begin set @i=@i+1 fetch next from cursor1…
//遍历tmp_check的年份和月份 DECLARE @year ) DECLARE @month ) DECLARE cur CURSOR FOR SELECT nf,yf FROM tmp_check; OPEN cur fetch next from cur into @year,@month ) begin print(@year) print(@month) //在这做其它的事 fetch next from cur into @year,@month end close cur D…
/* table1结构如下 id int name varchar(50) */ declare @id int ) declare cursor1 cursor for --定义游标cursor1 select * from table1 --使用游标的对象(跟据需要填入select文) open cursor1 --打开游标 fetch next from cursor1 into @id,@name --将游标向下移1行,获取的数据放入之前定义的变量@id,@name中 --判断是否成功获…