ALTER TABLE FV_REPLICATE_LOG ADD DATE_SENT TIMESTAMP DEFAULT CURRENT_TIMESTAMP;

SET TERM ^ ;

CREATE OR ALTER PROCEDURE SEL_FV_LOG (
    PID_REP INTEGER,
    PDATE DATE)
RETURNS (
    ID_REP INTEGER,
    RAZ_SOC VARCHAR(100),
    VERSAO_FV VARCHAR(20),
    DATE_SENT TIMESTAMP,
    TEXT_LOG VARCHAR(2000))
AS
BEGIN
  FOR
    SELECT PESSOA.ID_PES,
           PESSOA.RAZ_SOC,
           FV_REPLICATE_LOG.TEXT_LOG,
           FV_REPLICATE_LOG.VERSAO_FV,
           FV_REPLICATE_LOG.DATE_SENT
    FROM PESSOA JOIN REPRES ON (PESSOA.ID_PES = REPRES.ID_PES)
    JOIN FV_REPLICATE_LOG ON (FV_REPLICATE_LOG.ID_REP = REPRES.ID_PES)
    WHERE (PESSOA.ID_PES = :PID_REP AND CAST(FV_REPLICATE_LOG.DATE_SENT AS DATE) = :PDATE)
    INTO :ID_REP,
         :RAZ_SOC,
         :TEXT_LOG,
         :VERSAO_FV,
         :DATE_SENT
  DO BEGIN
    SUSPEND;
  END
END^

SET TERM ; ^


/* Following GRANT statetements are generated automatically */

GRANT SELECT ON PESSOA TO PROCEDURE SEL_FV_LOG;
GRANT SELECT ON REPRES TO PROCEDURE SEL_FV_LOG;
GRANT SELECT ON FV_REPLICATE_LOG TO PROCEDURE SEL_FV_LOG;

/* Existing privileges on this procedure */

GRANT EXECUTE ON PROCEDURE SEL_FV_LOG TO FORCA_V;
GRANT EXECUTE ON PROCEDURE SEL_FV_LOG TO SYSDBA;