我需要从列的内容中提取一个数字。该列包含一些地址数据和一个数字。
例如:
Col X
-----
Address ABCD 9889030292
adress OPQR
9834347473
ADDR HIJK 2382982381
3, AST STREET, 4545009234
BNG 3483472234
期望的输出:
Col Result
----------
9889030292
9834347473
2382982381
4545009234
3483472234
哪个SQL查询实现了这个目标?
答案 0 :(得分:0)
这适用于Oracle。我认为这也适用于MS SQL Server。
select upper(address) address,
trim(both from translate(upper(address),'!~@#$%^&*()`1234567890-=_+[]{};"/?.>,<',' ')) characters,
trim(both from translate(upper(address),'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%^&*();":[]{},.<>/?',' ')) numbers
from (
select 'Col X' address from dual
union all
select 'Address ABCD 9889030292' from dual
union all
select 'adress OPQR' from dual
union all
select '9834347473' from dual
union all
select 'ADDR HIJK 2382982381' from dual
union all
select '3, ast street, 4545009234' from dual
union all
select 'BNG 3483472234' from dual);