sql - 在SQL中从没有以下字符的字符串中提取数字
问题描述
所以我有如下街道地址:
123 Street Ave
1234 Road St Apt B
12345 Passage Way
现在,我很难在没有任何街道名称的情况下仅提取街道编号。
我只是想:
123
1234
12345
解决方案
正如您所说,两个简单的选项会返回所需的结果。一个使用正则表达式(选择字符串中的第一个数字),而另一个返回第一个子字符串(由空格分隔)。
SQL> with test (address) as
2 (select '123 Street Ave' from dual union all
3 select '1234 Road St Apt B' from dual union all
4 select '12345 Passage Way' from dual
5 )
6 select
7 address,
8 regexp_substr(address, '^\d+') result_1,
9 substr(address, 1, instr(address, ' ') - 1) result_2
10 from test;
ADDRESS RESULT_1 RESULT_2
------------------ ------------------ ------------------
123 Street Ave 123 123
1234 Road St Apt B 1234 1234
12345 Passage Way 12345 12345
SQL>
推荐阅读
- animation - 带有透明背景的 gif 动画
- python - 如何在急切执行模式下获取 keras 模型的可训练变量?
- c++ - 什么是“__static_initialization_and_destruction_0”以及如何解决这个问题?
- c# - PowerPoint 文件中的图表轴
- swift - 无法连接并输入字段到函数/类
- azure-devops - 安全按钮 Azure Devops 消失
- javascript - 通过 JavaScript 使用向上和向下箭头键启用滚动
- android - 蓝牙配置文件 A2DP 和 SPP 是否用于从蓝牙麦克风录制音频?
- python - python线程和它们之间的队列消息
- linux - 为什么挂载的 hostPath 在 GKE 的 kubernetes 上不起作用