|
出现ora-01476:除数为0错误时可以用decode函数解决:
decode (expression, search_1, result_1)
如果 expression结果=search_1结果,则返回result_1
decode (expression, search_1, result_1, search_2, result_2)
decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n)
decode (expression, search_1, result_1, default)
如果 expression结果=search_1结果,则返回result_1,否则反回default
decode (expression, search_1, result_1, search_2, result_2, default)
decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n, default)
decode函数比较表达式和搜索字,如果匹配,返回结果;如果不匹配,返回default值;如果未定义default值,则返回空值。
如:
select (a/b*100) as percent from t
如果b为0会出现被除数为0
解决:
select decode(b,0,0,a/b*100) as percent from t
|
|