tags:

views:

28

answers:

2

I want to find character code of particular character in string. For instance if I have a string

"Hello"

How do i find the character code of all or particular characters in the string.

I see that PL/SQL has a ASCII() and ASCIISTR() functions but I could not find any character related functions.

A: 

What exactly would you expect? Looking at your question, it seems to me that ASCII() would give you what you need, see this ASCII tutorial. You can loop

Or are you referring to the Unicode value?

Ernst de Haan
I want to iterate through a string and find all the character codes of the characters present in that string, I have yet to have a look at the link but I think ASCII() takes in a character as an argument for instance you would have to do ASCII('H') to get the character code of 'H'.
Kevin Boyd
Btw I have looked at the link and most of the examples are SQL I'm looking more for PLSQL. For eg. in actionscript I would have done something like this var str:String = "HELLO";var cCode:Number;for(var i=0; i<str.length; i++){ trace(str.charCodeAt(i));}will give result as 72, 69, 76, 76, 79
Kevin Boyd
You can use almost all SQL commands in PL/SQL directly, and where you cannot, you can use them by embedding SQL.
JulesLt
@JulesLt: Yes, possibly, I'm not that conversant with PL/SQL, however Michael's answers comes close to what I was looking for.
Kevin Boyd
The DUMP SQL command may be of use to.
JulesLt
+2  A: 
  create or replace function asciistr2(s IN varchar2)
  RETURN varchar2
  IS
    result varchar2(32767) := '';
  BEGIN
    FOR i IN 1..Length(s)
      LOOP
      dbms_output.put_line(ASCII(substr(s,i,1)));
      result := result || ASCII(substr(s,i,1));
      END LOOP;
      return result;
  END;


  Select asciistr2('HELLO') from dual

Result: 7269767679

dbms_output

 72
 69
 76
 76
 79
Michael Pakhantsov