How to convert a SQL Server cursor to MySQL?
ALTER function [dbo].[Terlambat](@proses int) returns @tempKK table (krk int,terlambat int) as 
begin
declare @uid int, @total_hari_kerja int
select @total_hari_kerja = SUM(alokasi)  from proses 
declare krk_uid cursor for select distinct krk from kartu_kendali where proses <= 8
open krk_uid
fetch next from krk_uid into @uid
while (@@FETCH_STATUS = 0)
begin
insert into @tempKK select top 1 krk, dbo.GetTerlambat(realisasi_tgl_terima, @total_hari_kerja) terlambat from kartu_kendali where proses = 1 and krk = @uid order by RecID
fetch next from krk_uid into @uid
end 
close krk_uid
deallocate krk_uid
return 
end
 
     
     
    