sorting - Enumerate rows alphabetized in Oracle -


i wonder if possible in oracle replace row number (we can use row_number() example digit) alfabetical numbering

let's like

no | name | surname ================  | john | doe b  | | doe c  | jim  | wonder 

instead of

no | name | surname | ================= 1  | john | doe 2  | | doe 3  | jim  | wonder 

i have idea create variable "abcdefg" , convert row number correct substr, sounds little unstable

temporary solution a-z use

chr((row_number() on (partition somecolumn order 1))+64) 

i created function converts number characters:

create or replace function num_to_char(p_number in number) return varchar2   v_tmp    number;   v_result varchar2(4000) := ''; begin   v_result := chr(mod(p_number - 1, 26) + 65);   if p_number > 26     v_result := num_to_char(trunc((p_number-1)/26)) || v_result;   end if;   return v_result; end num_to_char; / 

you can use in selects:

select num_to_char(row_number() on (partition dummy order 1)) dual connect level < 3000 

1 - a, 2 - b, ... , 25 - y, 26 - z, 27 - aa, 28 - ab, ..., 703 - aaa, 704 - aab, ...


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -