text: WITH LANC_POR_MES_ANO AS (
      SELECT L.RECNUM,
             TO_NUMBER (TO_CHAR (L.DTCOMPETENCIA, 'YYYY') || TO_CHAR (L.DTCOMPETENCIA, 'MM')) AS MES_DTCOMPETENCIA,
             TO_NUMBER (TO_CHAR (L.DTLANC, 'YYYY') || TO_CHAR (L.DTLANC, 'MM')) AS MES_DTLANC
        FROM PCLANC L
  )
  SELECT L.ROWID,
         L.DTCOMPETENCIA,
         L.DTEMISSAO,
         L.DTLANC,
         L.RECNUM,
         L.CODCONTA,
         L.HISTORICO,
         L.DTPAGTO
    FROM PCLANC L
   INNER JOIN LANC_POR_MES_ANO A ON L.RECNUM = A.RECNUM
    LEFT JOIN PCCONTA C ON L.CODCONTA = C.CODCONTA
   WHERE ((L.DTCOMPETENCIA > TRUNC (SYSDATE)
     AND L.DTPAGTO IS NOT NULL)
      OR (L.DTCOMPETENCIA < L.DTEMISSAO - 30)
      OR (L.VALOR < 0
     AND A.MES_DTCOMPETENCIA <> MES_DTLANC
     AND L.NUMBANCO = 41
     AND L.DTCOMPETENCIA <= L.DTLANC - 10))
     AND L.DTEMISSAO >= TO_DATE ('01/01/2020', 'DD/MM/YYYY')
     AND L.DTESTORNOBAIXA IS NULL
     AND L.DTLANC >= TO_DATE ('01/02/2021', 'DD/MM/YYYY')
     AND C.GRUPOCONTA NOT IN (
      610, 620, 650
  );
  /