我的表中有超过 200 000 条数据,其中一列具有特殊字符 'Æ??`,文本为 test1234Æ??。如何用“?”替换它符号?
答案 0 :(得分:0)
Æ 有 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 和逗号范围内的字符,您可以使用正则表达式。对此还有很多其他答案,例如 this one。
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;