从 Oracle 表中删除非 ASCII 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3319262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove non-ASCII values from Oracle table
提问by shubhra
How can you remove non-ASCII values from a table in Oracle with PL/SQL?
如何使用 PL/SQL 从 Oracle 中的表中删除非 ASCII 值?
回答by Tom
Assuming that you have a table with a VARCHAR2 column that contains some non-alphanumeric characters, then you can replace them with an SQL statement. You might start with something like this and refine it to suit your needs:
假设您有一个包含一些非字母数字字符的 VARCHAR2 列的表,那么您可以将它们替换为 SQL 语句。您可以从这样的事情开始,然后对其进行改进以满足您的需求:
UPDATE mytable x
SET x.col = REGEXP_REPLACE(x.col, '[^[:alnum:] ]', ' ')
WHERE REGEXP_LIKE (x.col, '.*[^[:alnum:]].*')
This statement uses regular expressions in an attempt to replace all the non-alphanumeric characters with spaces. You will probably need to make adjustments if you want to leave other desired characters, like commas, in place.
此语句使用正则表达式尝试用空格替换所有非字母数字字符。如果您想保留其他所需字符(如逗号),您可能需要进行调整。
Of course, if your needs are massively more complicated than replacing a few characters in a couple of columns then you might need to take a different approach. If this is the case, then perhaps you could expand your question to give more information about your specific problem.
当然,如果您的需求比替换几列中的几个字符要复杂得多,那么您可能需要采取不同的方法。如果是这种情况,那么也许您可以扩展您的问题以提供有关您的特定问题的更多信息。