Home » SQL & PL/SQL » SQL & PL/SQL » string to CHR
string to CHR [message #20475] Tue, 28 May 2002 02:21 Go to next message
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 #20478 is a reply to message #20475] Tue, 28 May 2002 04:23 Go to previous messageGo to next message
Vikas Gupta
Messages: 115
Registered: February 2002
Senior Member
Use this:

select
ascii(substr('ABC',1,1)) +
ascii(substr('ABC',2,1)) +
ascii(substr('ABC',3,1))
from dual;

Regards,
Re: string to CHR [message #20480 is a reply to message #20475] Tue, 28 May 2002 07:19 Go to previous message
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;
Previous Topic: Problem of create trigger
Next Topic: Oracle 600 message
Goto Forum:
  


Current Time: Thu Apr 25 17:31:51 CDT 2024