sql - 如何使用 Oracle regexp_replace 删除数字之间的空格和特殊字符
问题描述
我需要删除 Oracle 和 Netezza 文本字段中数字之间的所有空格和特殊字符。
Input:
[Any text 00 00 111 1 2222 ,?/!@#$ 33333 any text 123,. 45].
Output:
[Any text 0000111222233333 any text 123.45]
谢谢!
解决方案
您可以使用
SELECT REGEXP_REPLACE(col,'[^0-9]') AS new_col
FROM tab
或[:digit:]
posix,例如
SELECT REGEXP_REPLACE(col,'[^[:digit:]]') AS new_col
FROM tab
为了删除所有非数字字符,包括空格。
更新:取决于您添加的请求
SELECT ID,
col,
CASE
WHEN REGEXP_INSTR(col, '[[:digit:]]') != 1 THEN
REPLACE(REGEXP_SUBSTR(col, '[^[:digit:][:punct:]]+'), ' ')
END ||
REGEXP_REPLACE(col, '[^0-9]*([0-9]+|$)', '\1') ||
REGEXP_SUBSTR(REGEXP_REPLACE(col, '[[:punct:] ]'), '[^[:digit:]]+$') AS new_col
FROM tab
将删除从第一个数字到最后一个数字的任何非数字字符,并保持外部部分不变。
推荐阅读
- javascript - 如何使用 Knex.js 在 Mysql 列中使用枚举类型设置默认值?
- google-optimize - 在 Google Optimze 中使用号召性用语跟踪标题更改
- installation - Ocaml Manual installation vs Graphical installation
- python - 如何创建一个功能来显示是否有人发表了评论?
- hy - 为什么我的 Hy unknown 和 deftag 版本未定义?
- java - Java接口合成方法生成同时缩小返回类型
- javascript - 如何循环并选择附加元素以获取 .text() 和 .data() 值?
- javascript - 为什么我的 JavaScript setter 没有按预期更改对象属性?
- c# - 显示连接的wifi密码C#
- javascript - 是否有可能从 async/await 获得“进行中”响应,然后在等待完成之前使用它来显示服务器当前正在做什么?