Sybase:循环调用存储过程
一、日期循环
declare @c_count int
declare @rq int
select @c_count=0
--获取两个日期之间的天数
select DateDiff(day,20170101,getdate())
while @c_count<=541
begin
select convert(numeric(8,0),CONVERT(varchar(8),dateadd(dd,@c_count,20170101),112)) into @rq
exec DBA.P_PROESS(@rq)
select @c_count= @c_count +1
end
二、游标循环
declare @c_orgname varchar(50);
declare @c_pk_deptdoc varchar(20);
declare c_zborg dynamic scroll cursor
for select a.orgname,a.pk_deptdoc from table1;
-- 打开游标
open c_zborg with hold;
fetch next c_zborg into @c_orgname, @c_pk_deptdoc;
-- 循环所有行
while @@SQLSTATUS = 0 loop
insert into dba.table2(orgname,pk_deptdoc) values(@c_orgname,@c_pk_deptdoc);
fetch next c_zborg into @c_orgname, @c_pk_deptdoc;
end loop;
-- 关闭游标
close c_zborg;
--释放资源
deallocate cursor c_zborg;
--end