I\'ve encountered here an inusited situation that I couldn\'t understand. Nor the documentation of the functions that I will write about has something to light up this thing
The function "nlssort()" return binary with extra 00 at the end of original binary of string.
Testing:
select NLSSORT('abc') from dual
Output:
61626300
this problem can be resolved by removing last 2 digits from NLSSORT's return.
Solution:
select a, length(a), b, length(b)
from ( select 'FGHJTÓRYO DE YHJKS DA DGHQÇÃA DE ASGA XCVBGL EASDEÔNASD' a,
replace(
utl_raw.cast_to_varchar2(
substr(nlssort('FGHJTÓRYO DE YHJKS DA DGHQÇÃA DE ASGA XCVBGL EASDEÔNASD', 'nls_sort=binary_ai'),1,
length(nlssort('FGHJTÓRYO DE YHJKS DA DGHQÇÃA DE ASGA XCVBGL EASDEÔNASD', 'nls_sort=binary_ai'))-2
)
)
,' ','_') b
from dual
)
)