Strange behavior of LENGTH command - ORACLE

前端 未结 3 1845
既然无缘
既然无缘 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:35

    1) Oracle distinguishes lengths in bytes and lengths in characters: varchar2(55) means 55 bytes, so 55 UTF-8 characters fit only if you are lucky: you should declare your field as varchar2 (55 char).

    2) Contortions like

    replace(utl_raw.cast_to_varchar2(nlssort(
    'FGHJTÓRYO DE YHJKS DA DGHQÇÃA DE ASGA XCVBGL EASDEÔNASD', 
    'nls_sort=binary_ai')),' ','_') b
    

    are nonsense, you are merely replacing strings with somewhat similar ones. Your database has an encoding, and all strings are represented with that encoding, which determines their length in bytes; the arbitrary variations mcalmeida explains introduce random data-dependent noise, never a good thing if you are making comparisons.

    3) Regarding the stated task of removing accents, you should do it yourself with REPLACE, TRANSLATE etc. because only you know your requirements; it isn't Unicode normalization or anything "standard", there are no shortcuts. You can define a function and call it from any query and any PL/SQL program, without ugly copying and pasting.

提交回复
热议问题