add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
DECLARE
TOT NUMBER:=0;
CNT NUMBER:=0;
AVG1 NUMBER:=0;
A NUMBER:=5;
B NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('A ====='||A);
WHILE(CNT > A)
LOOP
TOT := TOT+ A;
CNT := CNT + 1;
END LOOP;
AVG1:= TOT/CNT;
DBMS_OUTPUT.PUT_LINE('AVERAGE ============'|| AVG1);
END;
/


dbms_output:
A =====5
ORA-01476: divisor is equal to zero
ORA-06512: at line 14
DECLARE
TOT NUMBER:=0;
CNT NUMBER:=0;
AVG1 NUMBER:=0;
A NUMBER:=5;
B NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('A ====='||A);
WHILE(CNT < A)
LOOP
TOT := TOT+ A;
CNT := CNT + 1;
END LOOP;
AVG1:= TOT/CNT;
DBMS_OUTPUT.PUT_LINE('AVERAGE ============'|| AVG1);
END;
/
1 rows affected

dbms_output:
A =====5
AVERAGE ============5
DECLARE
A NUMBER:=5;
CNT NUMBER:=GREATEST(A,0);
TOT NUMBER:=CNT*A;
AVG1 NUMBER:=TOT/CNT;
BEGIN
DBMS_OUTPUT.PUT_LINE('A ====='||A);
DBMS_OUTPUT.PUT_LINE('AVERAGE ============'|| AVG1);
END;
/
1 rows affected

dbms_output:
A =====5
AVERAGE ============5