使用此功能时出现零除错误。它编译良好。由于我没有使用select语句,因此我假设NULLIF无效。
如何避免零除问题?

    OPEN GET_DATA;
    fetch GET_DATA into v_gpa_hsch,v_gpa_hsch_scale,v_gpa_scale,v_gpa,
     v_gpa_recalc,v_gpa_hsch_recalc;
    IF GET_DATA%NOTFOUND
    THEN
    IT_final_final_calc :=0;

    ELSE
            IF  v_gpa_hsch_scale < v_gpa_scale
            THEN IL_higher_scale_calc := v_gpa_scale;
            ELSE IL_higher_scale_calc := v_gpa_hsch_scale;
            END IF;

            IF v_gpa_hsch < v_gpa
            THEN IM_gpa_calc := v_gpa;
            ELSE IM_gpa_calc := v_gpa_hsch;
            END IF;

            IF IM_gpa_calc > IL_higher_scale_calc
            THEN IN_highest_gpa_calc := IL_higher_scale_calc;
            ELSE IN_highest_gpa_calc := IM_gpa_calc;
            END IF;

            IO_factor_calc := (IL_higher_scale_calc/4);

            --I PRESUME THE FOLLOWING LINE IS THE ISSUE:
            IP_rec_calc := +(IN_highest_gpa_calc/IO_factor_calc);

最佳答案

您可以根据需要使用这两个选项,

使用CASE

IP_rec_calc := CASE IO_factor_calc WHEN 0 then 0 --whatever you want
                    ELSE +(IN_highest_gpa_calc/IO_factor_calc)
                    END;


zero_divide异常处理程序

EXCEPTION
 WHEN zero_divide then
    dbms_output.put_line('Division by Zero happened .');
IP_rec_calc := 0; --whatever you want

关于oracle - 如何在Oracle函数中处理零除,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54425432/

10-11 02:42