删除 SQL Oracle 中的所有数字字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21464759/
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 all the numeric characters in SQL Oracle
提问by user2545602
I want to remove all the numeric characters from a string in SQL, e.g. Fr?n Japan samtal till 0046709757417
我想从 SQL 中的字符串中删除所有数字字符,例如 Fr?n Japan samtal 直到 0046709757417
I want the output to be Fr?n Japan samtal till
我希望输出是 Fr?n Japan samtal 直到
thanks.
谢谢。
回答by Gordon Linoff
You can use the translate()
function (see here):
您可以使用该translate()
功能(请参阅此处):
select translate(col, 'a0123456789', 'a')
This function replaces the characters is in the first string with the corresponding characters in the second string. The 'a'
is because of a peculiarity of Oracle. Oracle treats the empty string (''
) as NULL
, and translate()
returns NULL
if any of the arguments are NULL
. The 'a'
allows the second argument to have a value.
此函数将第一个字符串中的字符替换为第二个字符串中的相应字符。这'a'
是因为 Oracle 的一个特殊性。Oracle 将空字符串 ( ''
) 视为NULL
,如果任何参数为,则translate()
返回。所述允许的第二个参数有一个值。NULL
NULL
'a'
Hereis a db<>fiddle.
这是一个 db<>fiddle。
回答by a_horse_with_no_name
regexp_replace('Fr?n Japan samtal till 0046709757417', '[0-9]', '')
SQLFiddle example: http://sqlfiddle.com/#!4/d41d8/24449
SQLFiddle 示例:http://sqlfiddle.com/#!4/d41d8/24449