今天在用之前的一個看磁盤消耗最多的sql時居然提示了一個報錯,之前明明還可以用的,報錯信息如下:ORA-01476:divisor is equal to zero.
看報錯很明顯是ORACLE中進行除的時候出現了除數為0,加個判斷條件或者decode()改寫就可以了。
假設是a/b,用函數decode(b,0,null,a/b) ,這樣如果b為0,輸出null,不為0輸出a/b
SELECT * FROM (SELECT sql_fulltext AS sql, SQL_ID, decode(executions,0,null,disk_reads/executions) AS "Reads/Exec", disk_reads, executions FROM V$SQLAREA v WHERE disk_reads > 1000 ORDER BY "Reads/Exec" DESC) WHERE rownum <= 10;
改寫成如下:
SELECT * FROM (SELECT sql_fulltext AS sql, SQL_ID, disk_reads/executions AS "Reads/Exec", disk_reads, executions FROM V$SQLAREA v WHERE disk_reads > 1000 and executions>0 ORDER BY "Reads/Exec" DESC) WHERE rownum <= 10;
覺得有用的朋友多幫忙轉發哦!後面會分享更多devops和DBA方面的内容,感興趣的朋友可以關注下~
,
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!