Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> need help with simple Function
I'm new to PL/SQL, need help with what should be (I think) a simple problem.
I'm trying to sum the digits in a number, here's what I have so far:
CREATE OR REPLACE FUNCTION Session_Hash
(sessid IN NUMBER ) RETURN NUMBER IS
dig_sum INTEGER; sesschar VARCHAR2(8);
dig_sum := dig_sum + TO_NUMBER(SUBSTR(sesschar,i,1));
END LOOP;
RETURN(dig_sum);
END;
/
This way it ends up returning nothing. If I change the line inside the loop to:
dig_sum := TO_NUMBER(SUBSTR(sesschar,i,1));
it returns the last digit in the number (so I know it is getting the number), but I need it to sum all of the digits.
Please tell me what I am doing wrong. Received on Wed Jan 12 2005 - 01:17:41 CST
![]() |
![]() |