2

I have some problems with characters not allowed in XML-export. The request is simply to remove the invalid characters from the text to ensure corrext export/import of data.

so far, thanks to this post I have an sql statement which replaces one declared Unicode char:

UPDATE mytable SET myproperty = replace(myproperty, U&'\UNICODE', '');

It removes the specified Unicode from all occurrences inside the defined cell. But I would like to give a bunch of Unicode chars to be replaced, eg. 0x1 - 0xf Does anybody have an idea how to achieve that?

1 Answer 1

5

Use TRANSLATE to remove multiple characters:

TRANSLATE(myproperty, 'list of characters', '');

Normally it's used to replace characters, but if the replacement string is empty it's removing them.

Edit:

Of course you can also use a regular expression, this allows ranges of characters:

regexp_replace(myproperty, '[\u0041-\u0043a]', '', 'g')

Adding the 'g' flag to replace all occurrences...

Sign up to request clarification or add additional context in comments.

8 Comments

thanks @dnoeth, that helps a little. do you know a way to set a range of codes? I tried that out but it does not work (eg. U&'[\0041-\0043]')
@RuthiRuth: There's no way to specifiy a range in TRANSLATE, but there's REGEXP_REPLACE. I modify my answer...
I tried that but then I get only the first occurrence in "myproperty" and not all occurences...
I got it, I have to set the flag 'g' to replace it with all occurrences. if you could edit your answer @dnoeth I can mark it as right :)
@RuthiRuth: Thanks, every DBMS has it's own rules regarding regex. Added it to my answer...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.