Friday 29 June 2012

Sum Of Digit's In PL/SQL


set serveroutput on
declare
N number(5);
s number(5):=0;
r number(5);
d number(5);
begin
n:=&N; 
while N<>0 loop
d:=mod(N,10);
s:=s+r+d;
end loop;
dbms_output.put_line('sum of digits is-'||s);
end;
/

1 comment:

  1. Logic is wrong because there is no quotient value in your program. see once,
    i think in s:=s+r+d; statement 'r' is not initialized. It is r:=(n/10);
    then only possible. Thank you.

    ReplyDelete