UNPIVOT通过数据库链接返回错误结果

时间:2019-01-24 12:48:18

标签: sql oracle unpivot

我对实现指向远程表的UNPIVOT的查询有问题。出于某种原因,它实际上返回了数据(附加查询向下),却返回空结果。

RESULT QUERY

我意识到问题可能出在Oracle版本之间,尽管我不确定。

这发生在别人身上吗?

任何解决方案?

查询:

` WITH TABLA1_RAW AS (SELECT   /*MATERIALIZE*/
                            a.fecha,
                            A.MIB_PLATAFORM,
                            A.RE_IP,
                            A.PATH_OID,
                            A.MIB_SECTION,
                            A.MIB_TYPE,
                            A.TYPE_VALOR,
                            A.VALOR,
                            INSTR(PATH_OID, '.', -1)                                            ULTIMO_PUNTO,
                            INSTR(SUBSTR(PATH_OID, 1, INSTR(PATH_OID, '.', -1) -1), '.', -1)    PENULTIMO_PUNTO
                    FROM CALIDAD@PRUEBA.WORLD A
                    WHERE FECHA BETWEEN TO_DATE('22.01.2019 00','DD.MM.YYYY HH24')
                                    AND TO_DATE('22.01.2019 01','DD.MM.YYYY HH24') + (3599/86400)
                          AND A.MIB_PLATAFORM = 'SDWAN'
                    ORDER BY FECHA),
      TABLA2_RAW AS (SELECT
                            FECHA,
                            MIB_PLATAFORM,
                            RE_IP,
                            PATH_OID,
                            MIB_SECTION,
                            MIB_TYPE,
                            TYPE_VALOR,
                            SUBSTR(PATH_OID, 1, ULTIMO_PUNTO - 1)                                                    PATH_MIB,
                            SUBSTR(PATH_OID, ULTIMO_PUNTO + 1, PENULTIMO_PUNTO - 1)                                  INSTANCIA,
                            VALOR,
                            NVL(LAG(VALOR, 1) OVER(PARTITION BY MIB_PLATAFORM,MIB_TYPE,MIB_SECTION,RE_IP,PATH_OID
                                              ORDER BY FECHA), VALOR)                                                 L_VALOR
                     FROM TABLA1_RAW),
     TABLE_RAW AS (SELECT /*MATERIALIZE*/
                          FECHA,
                          MIB_PLATAFORM,
                          RE_IP,
                          PATH_OID,
                          MIB_SECTION,
                          MIB_TYPE,
                          TYPE_VALOR,
                          PATH_MIB,
                          INSTANCIA,
                          VALOR,
                          l_valor,
                          CASE WHEN TYPE_VALOR = 'Counter32'
                                THEN NVL(DECODE(L_VALOR, 0, 0, CASE WHEN L_VALOR > VALOR
                                   THEN CASE WHEN (POWER(2, 32) + VALOR - L_VALOR)  > POWER(2, 60)
                                      THEN 0
                                      ELSE (POWER(2, 32) + VALOR - L_VALOR)
                                      END
                                   ELSE DECODE(L_VALOR, 0, 0, (VALOR - L_VALOR))
                                   END), 0)
                                END                                                                   N_VALOR
                   FROM TABLA2_RAW
                   WHERE PATH_MIB NOT IN ('1')),
     TABLA1_HOUR AS (SELECT FECHA,
                                  --(SELECT TO_CHAR(TRUNC(FECHA,'HH24'),'DD.MM.YYYY HH24')                FECHA,
                                                                                                        RE_IP,
                                                                                                        INSTANCIA,
                            ROUND(AVG(DECODE(PATH_MIB,'1',VALOR)))           CPU_LOAD,
                            ROUND(AVG(DECODE(PATH_MIB,'1',VALOR)))          MEMORY_AVAILABLE,
                            ROUND(AVG(DECODE(PATH_MIB,'1',VALOR)))           MEMORY_USED,
                            ROUND(AVG(DECODE(PATH_MIB,'1',VALOR)))   FLASH_CAPACITY,
                            ROUND(AVG(DECODE(PATH_MIB,'1',VALOR)))   FLASH_USED,
                            ROUND(AVG(DECODE(PATH_MIB,'1',VALOR)))       CONECTIONS,
                            ROUND(AVG(DECODE(PATH_MIB,'1',N_VALOR)))                 TRAFICO_ENTRANTE_KB
                     FROM TABLE_RAW
                     GROUP BY FECHA,--TO_CHAR(TRUNC(FECHA,'HH24'),'DD.MM.YYYY HH24'),
                              RE_IP,
                              INSTANCIA,
                              DECODE(PATH_MIB,'',VALOR)
                    ),
     TABLE_HOUR AS(SELECT                                                         FECHA,
                                                                                  RE_IP,
                                                                                  INSTANCIA,
                                                                                  CPU_LOAD,
                     ROUND(MEMORY_USED/DECODE(MEMORY_USED+MEMORY_AVAILABLE,
                     0,1,MEMORY_USED+MEMORY_AVAILABLE),2)*100                     MEMORY_UTILIZATION,
                                                                                  MEMORY_AVAILABLE,
                                                                                  MEMORY_USED,
                     ROUND(FLASH_USED/DECODE(FLASH_CAPACITY,
                     0,1,FLASH_CAPACITY),2)*100                                   FLASH_UTILIZATION,
                                                                                  FLASH_CAPACITY,
                                                                                  FLASH_USED,
                                                                                  CONECTIONS,
                                                                                  TRAFICO_ENTRANTE_KB
                   FROM TABLA1_HOUR
                  )
SELECT FECHA,
       RE_IP,
       INSTANCIA,
       NOMBRE_KPI,
        VALOR_KPI
FROM  TABLE_HOUR
UNPIVOT INCLUDE NULLS
(VALOR_KPI FOR (NOMBRE_KPI) IN
  (CPU_LOAD                AS  'CPU_LOAD',
   MEMORY_UTILIZATION      AS  'MEMORY_UTILIZATION',
   MEMORY_AVAILABLE        AS  'MEMORY_AVAILABLE',
   MEMORY_USED             AS  'MEMORY_USED',
   FLASH_UTILIZATION       AS  'FLASH_UTILIZATION',
   FLASH_CAPACITY          AS  'FLASH_CAPACITY',
   FLASH_USED              AS  'FLASH_USED',
   CONECTIONS              AS  'CONECTIONS',
   TRAFICO_ENTRANTE_KB     AS  'TRAFICO_ENTRANTE_KB'))`

1 个答案:

答案 0 :(得分:0)

似乎是一个已知的错误[文档ID 2370554.1

Seem to be a know bug [Doc ID 2370554.1