Para evitar errores con la inicialización de variables como V_DATO, yo prefiero utilizar IF EXISTS(...).
- Te ahorras la variable
- Te ahorras tener que inicializarla
- Te ahorras tener que pensar si tiene valores basura de otros usos.
- Es una instrucción optimizada que corta el SELECT en cuanto encuentra algo y no tiene que ir creando la respuesta con los registros encontrados.
Mira si te deja compilar así:
Código SQL
[-]
if (not exists(select *
from lecheria_a_lecheria c
where c.clave_lec_origen=:v_lec_sede
and c.clave_lec_destino=:v_lecheria)) then
begin
if (not exists(select *
from lecheria_a_lecheria c
where c.clave_lec_origen=:v_lecheria
and c.clave_lec_destino=:v_lec_sede)) then
begin
INSERT INTO ERR_COMBINACIONES (ERR_LEC_ORIGEN,
ERR_LEC_DESTINO,
ERR_RUTA,
ERR_FECHA_VISITA)
values (:v_lecheria,
:v_lec_sede,
:v_ruta,
:v_fecha_visita);
end
end