CREATE TABLE t (name) AS
SELECT 'Hello World' FROM DUAL UNION ALL
SELECT 'Acx÷×' FROM DUAL UNION ALL
SELECT '123 456 789' FROM DUAL UNION ALL
SELECT '~!@#$%Xxv^&*()_+=\sv{}[]:”;’<,>./?' FROM DUAL
SELECT TRANSLATE(name, '~!@÷*#$%^&*()_+=\{}[]:”;’<,>./?',' ') as no_special_char
FROM t;
NO_SPECIAL_CHAR
Hello World
Acx×
123 456 789
Xxvsv
with tbl(id, str) as (
select 1, 'test' from dual union all
select 2, 'test 1 test' from dual union all
select 3, 'test 2' from dual union all
select 4, '3 test' from dual union all
select 5, '4 ` test' from dual union all
select 6, 'test ~ test' from dual
)
select id, str
from tbl
where regexp_like(str, '[0-9]$') -- ends in a number
or regexp_like(str, '\d') -- contains a number anywhere
or regexp_like(str, '[[:punct:]]'); -- contains a punctuation character anywhere
ID STR
---------- -----------
2 test 1 test
3 test 2
4 3 test
5 4 ` test
6 test ~ test
5 rows selected.
2条答案
按热度按时间iezvtpos1#
可以使用“翻译”命令删除字符。
ajsxfq5m2#
使用WITH子句是设置测试数据的一种好方法,并且使尝试不同的测试字符串变得真实的容易。可以将其视为临时表。第一个
regexp_like()
测试字符串末尾的数字。请参见下面测试字符串中任意位置的数字。使用posix regex简写[[:punct:]]
匹配标点字符。我只是将所有示例合并到下面的一个查询中。