Write a PLSQL block to display sum of digit of a number.
Program:
DECLARE
N int:=56;
S int:=0;
R int:=0;
BEGIN
WHILE N !=0
LOOP
R:=MOD(N,10);
S:=S+R;
N:=TRUNC(N/10);
END LOOP;
DBMS_OUTPUT.PUT_LINE('SUM
OF DIGITS OF GIVEN NUMBER IS '||S);
END;
/
Output:
SUM OF
DIGITS OF GIVEN NUMBER IS 11
No comments:
Post a Comment