oracle11g - 替换Oracle数据库中的特殊字符
问题描述
我在一个表中有超过 200 000 个数据,其中一列具有特殊字符“Æ??”,文本为 test1234Æ??。如何用“?”替换它 象征?
解决方案
Æ 有 unicode 00C6。只需谷歌“Æ unicode”即可找到 - 有了这些知识,您就可以使用该UNISTR
函数来表示该字符。但是,如果您的客户端支持 unicode 字符,您也可以将该字符粘贴到您的 sql 中,如下所示。
WITH mystrings AS
(SELECT 'found a Æ in this text' as str FROM DUAL UNION ALL
SELECT 'text is test1234Æ??' FROM DUAL
)
SELECT
REPLACE(str,UNISTR('\00c6'),'?') as clean_string,
REPLACE(str,'Æ','?') as clean_string2,
REPLACE(str,UNISTR('\00c6??'),'?') as clean_stringnoqm
FROM mystrings;
CLEAN_STRING CLEAN_STRING2 CLEAN_STRINGNOQM
----------------------- ----------------------- -----------------------
found a ? in this text found a ? in this text found a Æ in this text
text is test1234??? text is test1234??? text is test1234?
如果您只想保留 a-zA-Z 和逗号范围内的字符,则可以使用正则表达式。周围还有很多其他答案,例如这个。
WITH mystrings AS
( SELECT
'Brand1® is supercool, but I prefer bRand2™ since it supports Æ' AS str
FROM dual
)
SELECT
regexp_replace(str,'[^A-Za-z0-9, ]', '?') AS clean_string
FROM mystrings;
推荐阅读
- python - 使用 python 从站点获取文本
- pine-script - 是否有可以在策略中使用的函数而不是 line.new() 或 label.new()?
- angular - 类型'可观察的
' 缺少属性 - java - 如何将 Volley StringRequest 响应转换为 JSONArray?
- arduino - 有没有办法使用arduino和gsm模块一次拨打多个电话号码?
- c# - C#中受保护的方法继承
- angular - 我可以一次在 2 个地方显示相同的组件实例吗?
- android - 在 Kotlin 中扩展的 Java 中的执行方法
- swift - “NSWindow 检测到过多的活动窗口计数”
- javascript - 绕过 Google Recaptcha for imacros