SybaceIQ游标的使用

ALTER PROCEDURE "DBA"."pro_tools_HandlePercent2"(@monthCount int,@targeBiz varchar(9999),@mySql varchar(9999),@pzTableName varchar(500))
begin       
    declare eof exception for sqlstate value '02000';
    declare cur_Aname cursor for select distinct colName from #tmpTB;  
   
		execute immediate 'select colName into #tmpTB from #rsColumns';
		 
    --迭代游标
    open cur_Aname with hold;
        _Atype: loop
                fetch cur_Aname into @colName;
                if sqlstate = eof then leave _Atype
                end if;
                
                set @sql = 'select * into #temp from (select ' + @colName + ' ' + @tt + ') pp order by ' + @colName + ' asc;';
                
                execute(@sql);
                        
        end loop _Atype;
    close cur_Aname;
	 
    commit;
end

你可能感兴趣的:(sql,exception,mysql,tools)