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()
the way to go ? For example something like:
MY_VALUE := TRANSLATE(MY_VALUE, CHR(9) || CHR(10) || CHR(11) || CHR(12) || CHR(13) || ' ', '');
Or is there any better alternative (something like [:space:]
in PHP PCRE) ?
Thanks for any piece of advice.
Answers. Use TRIM, LTRIM, RTRIM and REPLACE (if needed).
The Oracle REGEXP_REPLACE() function replaces a sequence of characters that matches a regular expression pattern with another string. The REGEXP_REPLACE() function is an advanced version of the REPLACE() function.
I'd go for regexp_replace, although I'm not 100% sure this is usable in PL/SQL
my_value := regexp_replace(my_value, '[[:space:]]*','');
Shorter version of:
REGEXP_REPLACE( my_value, '[[:space:]]', '' )
Would be:
REGEXP_REPLACE( my_value, '\s')
Neither of the above statements will remove "null" characters.
To remove "nulls" encase the statement with a replace
Like so:
REPLACE(REGEXP_REPLACE( my_value, '\s'), CHR(0))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With