Strange behavior of LENGTH command - ORACLE

前端 未结 3 1826
既然无缘
既然无缘 2021-01-04 12:43

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

3条回答
  •  孤街浪徒
    2021-01-04 13:31

    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
         )
    
      )
    

提交回复
热议问题