If I understand your idea correctly, you can do something like this. Suppose there is a source:
with source as ( select 'abc' a from dual union all select 'def' a from dual union all select 'hij' a from dual) select * from source;
It is necessary to make a custom erase, so that the letter d goes first, and a - the second. Then:
with source as ( select 'abc' a from dual union all select 'def' a from dual union all select 'hij' a from dual) select a, sort_column from (select a, translate(a, 'adh', 'dah') sort_column from source) order by sort_column;
With the help of translate replace characters, the third parameter sets the necessary sorting. Next, sort by the result of the translation. Result:
A SORT_COLUMN --- ----------- def aef abc dbc hij hij
UPD.
A little bit about the principle of forming a string for the translate function. There is some built-in sequence. In this case, it is sorted simply in ascending ASCII codes. In the translate function, we pass the first string as the first parameter, the second as the existing sorting order, and the third as the conversion to the desired order. Here you can break the brain, so be careful. Your source line, existing sort order, conversion line:
0 2 9 BCE adf Д Ж Э б о р б о р Д Ж Э 0 2 9 adf BCE adf б о р Д Ж Э BCE 0 2 9 <-- это пойдет в функцию translate
You need to first go letter б , then о , then р and so on. In the existing sort order, the first is 0 (second line). Therefore, under б in the first line we write 0 in the third. Then о - under о we write 2 , and so on. For the complete alphabet, respectively, will be:
существующий порядок 0 1 2 3 4 5 6 7 8 9 ABC ... abc ... А Б В ... a б в ... э ю я строка замены а б в г д е ё ж з и к л м ................................. XYZ
The principle, I hope, is clear.
Then everything is solved in one request:
select listagg(letters) within group (order by srt) from (select letters, translate(letters, '029BCEadfДЖЭбор' /*существующий порядок*/, 'adfборДЖЭBCE029' /*строка замены*/) srt from (select substr('CBEdfa092борДЖЭ', level, 1) letters from dual connect by level <= length('CBEdfa092борДЖЭ')) ) RES ---------------- борДЖЭ029adfBCE
DECLARE str CONSTANT varchar2(32767) := 'CBEdfa092борДЖЭ';. I need to sort it by the "ЯЯ, 0..9, zZ" template in the anonymous block. - user214690