Propongo esta opción...Procedimiento almacenado en firebird
Código SQL
[-]
reate or alter procedure check_correlativos
returns (id_falta integer)
as
declare variable id integer;
declare variable id_next integer;
declare variable oldNext integer;
BEGIN
OldNext=-1;
FOR
select c.id, c.id+1
from articulos c
INTO :ID, :ID_NEXT
DO
BEGIN
id_falta=null;
if (OldNext=-1) then
OldNext=ID;
if (OldNext<>id) then
id_falta=OldNext;
OldNext=ID_NEXT;
if (not id_falta is null) then
suspend;
END
END