CREATE OR REPLACE PROCEDURE sp_fco_upd_diagnosticos
(
    pvc_diagnostico varchar2,
    pvc_descripcion varchar2
)
AS
    vti_existe number(1);
BEGIN

    vti_existe := 0;

    BEGIN
      SELECT 1
      INTO vti_existe
      FROM fco_diagnosticos
      WHERE diagnostico = pvc_diagnostico;
    EXCEPTION
      WHEN OTHERS THEN vti_existe := 0;
    END;

    IF vti_existe = 1 THEN 
        UPDATE fco_diagnosticos 
        SET descripcion = pvc_descripcion
        WHERE diagnostico = pvc_diagnostico;
    ELSE
        INSERT INTO fco_diagnosticos (diagnostico, descripcion)
        VALUES (pvc_diagnostico, pvc_descripcion);
    END IF;
    
    COMMIT WORK;
END;
/

CREATE PUBLIC SYNONYM sp_fco_upd_diagnosticos FOR ADAM.sp_fco_upd_diagnosticos;
GRANT EXECUTE ON sp_fco_upd_diagnosticos TO adama;

