Write a PL/SQL function to find the sum of digits of accepted nos.
set serveroutput on
create or replace function sm(no in number)return number as
i number(4);
sm number(4);
rem number(4);
num number(4);
begin
num:=no;
sm:=0;
i:=0;
while i<=num+1
loop
rem:=mod(num,10);
dbms_output.put_line(rem);
sm:=sm+rem;
num:=num/10;
i:=i+1;
end loop;
return sm;
end;
------------
set serveroutput on
declare
nos number(10);
ans number(3);
begin
nos:=&nos;
ans:=sm(nos);
dbms_output.put_line('Sum of Digit is '||ans);
end;
No comments:
Post a Comment