DROP MATERIALIZED VIEW FCT_MV_CCUSTO_CONTRATO
/

CREATE MATERIALIZED VIEW FCT_MV_CCUSTO_CONTRATO
AS
    SELECT CCUSTO.NRSEQCONTRATO,
           FCT_CONTRATO.NRSEQMODCONTRA,
           FCT_MODELOCONTRATO.NMMODCONTRATO,
           FCT_CONTRATO.CDOPERRESPONSAVEL,
           OPERADOR.NMOPERADOR,
           CCUSTO.NRCONTRATOFCT,
           CCUSTO.DTAPROVACAO,
           CCUSTO.NRSEQORCAMENTO,
           FCT_ORCAMENTO.NRORCAMENTOMODELO,
           FCT_ORCAMENTOMODELO.NMORCAMENTOMODELO,
           CCUSTO.NRORCAMENTO,
           CCUSTO.DTACEITEORCA,
           CCUSTO.NRTIPOORCAMENTO,
           CCUSTO.NMTIPOORCAMENTO,
           CCUSTO.IDTPFATURA,
           CCUSTO.DSTPFATURA,
           CCUSTO.IDSITUACAOCONTRATO,
           CCUSTO.NRPARCNEGOCIO,
           CCUSTO.NMPRINCIPALPARC,
           CCUSTO.NMSECUNDARIPARC,
           CCUSTO.NRINSCRICAOPARC,
           CCUSTO.NMITEMCONTRATO,
           CCUSTO.CDSERVORCA,
           CCUSTO.NMSERVORCA,
           CCUSTO.IDELEMENTO,
           CCUSTO.CDCENTCUST,
           CCUSTO.NMCENTCUST,
           CCUSTO.QTMEDIDAITEMCONT,
           CCUSTO.QTMEDIDAVARIAVEL,
           CCUSTO.CDTPMEDIDAVARIAVEL,
           CCUSTO.DSTPMEDIDAVARIAVEL,
           CCUSTO.VRTOTSERVORCA,
           CCUSTO.VRTOTAL_ACR_DESC,
           CCUSTO.IDDELPHI,
           CCUSTO.DTINICOMPET,
           CCUSTO.DTFINCOMPET,
           CCUSTO.QTMEDIDAMEDICAO,
           CCUSTO.VRITEMCONTCOMDESC,
           CCUSTO.NRORG
      FROM TABLE(FCT_CCUSTO_CONTRATO()) CCUSTO
      JOIN FCT_CONTRATO
        ON FCT_CONTRATO.NRSEQCONTRATO = CCUSTO.NRSEQCONTRATO
       AND FCT_CONTRATO.NRORG         = CCUSTO.NRORG
      JOIN FCT_MODELOCONTRATO
        ON FCT_MODELOCONTRATO.NRSEQMODCONTRA = FCT_CONTRATO.NRSEQMODCONTRA
       AND FCT_MODELOCONTRATO.NRORG          = FCT_CONTRATO.NRORG
      JOIN OPERADOR
        ON OPERADOR.CDOPERADOR = FCT_CONTRATO.CDOPERRESPONSAVEL
       AND OPERADOR.NRORG      = FCT_CONTRATO.NRORG
      JOIN FCT_ORCAMENTO
        ON FCT_ORCAMENTO.NRSEQORCAMENTO = CCUSTO.NRSEQORCAMENTO
       AND FCT_ORCAMENTO.NRORG          = CCUSTO.NRORG
      JOIN FCT_ORCAMENTOMODELO
        ON FCT_ORCAMENTOMODELO.NRORCAMENTOMODELO = FCT_ORCAMENTO.NRORCAMENTOMODELO
       AND FCT_ORCAMENTOMODELO.NRORG             = FCT_ORCAMENTO.NRORG
/
