UNPIVOT 通过数据库链接返回错误结果
Posted
技术标签:
【中文标题】UNPIVOT 通过数据库链接返回错误结果【英文标题】:UNPIVOT returns wrong results over db link 【发布时间】:2019-01-24 12:48:18 【问题描述】:我对实现指向远程表的 UNPIVOT 的查询有疑问。由于某种原因,它返回空结果,而实际上数据存在(附加查询已关闭)。
我意识到问题可能是 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'))`
【问题讨论】:
您是否尝试在更简单的示例中重现它?这种方法的优点是有时您会在 Oracle 中找到 not 的东西;) 似乎是一个已知的错误 [Doc ID 2370554.1]。解决方案是补丁或创建临时表 @TedatORCL.Pro 我用临时表做了一个测试,它奏效了,但这个解决方案并不能说服我。您知道任何可以为我提供解决方案的补丁吗?我执行查询的 oracle 版本是 12.2.0.1.0 到远程数据库 11.2.0.3.0。谢谢。 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit 向远程数据库 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit 下载似乎是一个已知的错误 [Doc ID 2370554.1
【讨论】:
以上是关于UNPIVOT 通过数据库链接返回错误结果的主要内容,如果未能解决你的问题,请参考以下文章