I have created a table as follows:
create table data_table(skey int, svalue int);
I want to find gaps in skey
. Say I have entries 1,2,6,7. Then running SQL should return 4 and 5. I referred this and tried executing following:
select @min_val := min(svalue), @max_val := max(svalue) from data_table;
create table tmp (Field_No int);
WHILE @min <= @max DO
if not exists (select * from data_table where skey = @min)
insert into tmp (Field_No) values (@min)
set @min = @min + 1
END WHILE;
select * from tmp
drop table tmp
MySQL workbench says WHILE is not valid input at this position
:
PS: Am using MySQL 5.6.25
Update
Adding the whole code in stored procedure still gives me errors: