我需要使用Reg_replace函数删除Oracle String Data中除连字符和空格以外的所有特殊字符。请提供帮助。例如:
输入->
My Name is #name1
输出->My Name is name1
输入->
this is my add-ress#"
输出->this is my add-ress
输入->
can we remov-e this';
输出->can we remov-e this
答案 0 :(得分:1)
您可以使用[^[:alnum:] -]
作为正则表达式来匹配要替换的值。
Oracle设置:
CREATE TABLE test_data( value ) AS
SELECT 'this is my add-ress#\' FROM DUAL UNION ALL
SELECT 'My Name is #name1' FROM DUAL UNION ALL
SELECT 'can we remov-e this' FROM DUAL;
查询:
SELECT value,
REGEXP_REPLACE( value, '[^[:alnum:] -]', NULL ) AS replaced_value
FROM test_data
输出:
VALUE | REPLACED_VALUE :-------------------- | :------------------ this is my add-ress#\ | this is my add-ress My Name is #name1 | My Name is name1 can we remov-e this | can we remov-e this
db <>提琴here
答案 1 :(得分:0)
您可以使用以下
with t(str) as
(
select 'this is my add-ress#&%! : 198' from dual
)
select regexp_replace(str,'[^-0-9A-Za-z ]','') as "Result String"
from t;
Result String
-----------------------
this is my add-ress 198