CREATE OR REPLACE PROCEDURE sp_fco_baja_fantasmas
(
    i_compania		char,
    i_trabajador  char
)
AS
	vnm_existe	number(1);
BEGIN
  
	vnm_existe := 0; 
	BEGIN
  	SELECT 1 INTO vnm_existe 
		FROM fco_fantasmas
    WHERE compania = i_compania 
		AND TRIM(trabajador) = TRIM(i_trabajador);
	EXCEPTION
		WHEN OTHERS THEN vnm_existe := 0;
	END;

	IF vnm_existe = 0 THEN
		raise_application_error(-20001, 'El registro a borrar en [fco_fantasmas] no existe');
		RETURN;
	END IF;

	BEGIN
    DELETE FROM fco_fantasmas
    WHERE compania = i_compania 
		AND TRIM(trabajador) = TRIM(i_trabajador);
	EXCEPTION
		WHEN OTHERS THEN 
		raise_application_error(-20001, 'Error al borrar de la tabla [fco_fantasmas]');
		RETURN;
	END;
	COMMIT WORK;
END;
/
CREATE PUBLIC SYNONYM sp_fco_baja_fantasmas FOR ADAM.sp_fco_baja_fantasmas;
GRANT EXECUTE ON sp_fco_baja_fantasmas TO adama;
