1.

Write PL/SQL program to find the sum of digits of a number.

Answer» DECLARE--Declare variables num, sum_of_digits and REMAINDER of datatype Integer num INTEGER; sum_of_digits INTEGER; remainder INTEGER; BEGINnum := 123456; sum_of_digits := 0;-- Find the sum of digits until original number DOESNT become null WHILE num <> 0 LOOP remainder := MOD(num, 10); sum_of_digits := sum_of_digits + remainder; num := TRUNC(num / 10); END LOOP; dbms_output.PUT_LINE('Sum of digits is '|| sum_of_digits); END;

Input: 9874
Output: 28



Discussion

No Comment Found