Oracle PL/SQL : remove “space characters” from a string

后端 未结 6 1921
迷失自我
迷失自我 2021-02-02 10:48

In my Oracle 10g database I would like to remove \"space characters\" (spaces, tabs, carriage returns...) from the values of a table field.

Is TRANSLATE() t

6条回答
  •  误落风尘
    2021-02-02 11:47

    To remove any whitespaces you could use:

    myValue := replace(replace(replace(replace(replace(replace(myValue, chr(32)), chr(9)),  chr(10)), chr(11)), chr(12)), chr(13));
    

    Example: remove all whitespaces in a table:

    update myTable t
        set t.myValue = replace(replace(replace(replace(replace(replace(t.myValue, chr(32)), chr(9)), chr(10)), chr(11)), chr(12)), chr(13))
    where
        length(t.myValue) > length(replace(replace(replace(replace(replace(replace(t.myValue, chr(32)), chr(9)), chr(10)), chr(11)), chr(12)), chr(13)));
    

    or

    update myTable t
        set t.myValue = replace(replace(replace(replace(replace(replace(t.myValue, chr(32)), chr(9)), chr(10)), chr(11)), chr(12)), chr(13))
    where
        t.myValue like '% %'
    

提交回复
热议问题