string to CHR [message #20475] |
Tue, 28 May 2002 02:21 |
Karri
Messages: 33 Registered: May 2001
|
Member |
|
|
Hi
I need help for this:
I have a string example: 'ABC'. Now I need to sum of CHR-char. In this case (65+66+67)=198.
How can I do this.
BR Karri
|
|
|
|
Re: string to CHR [message #20480 is a reply to message #20475] |
Tue, 28 May 2002 07:19 |
Paul
Messages: 164 Registered: April 1999
|
Senior Member |
|
|
The function below will sum the ascii values of all characters in a string
CREATE OR REPLACE FUNCTION ASCII_SUM(V_INPUT_STRING VARCHAR2)
RETURN NUMBER AS
V_CHKSUM NUMBER(10) := 0;
V_CHAR VARCHAR2(1);
V_LEN NUMBER(10) := LENGTH(V_INPUT_STRING);
BEGIN
FOR i IN 1..V_LEN LOOP
V_CHAR := SUBSTR(V_INPUT_STRING,i,1);
V_CHKSUM := V_CHKSUM + ASCII(V_CHAR);
END LOOP;
RETURN V_CHKSUM;
END;
|
|
|