在 BigQuery 中仅提取没有国家/地区代码的电话号码

问题描述 投票:0回答:1

我在 GCP BigQuery 中有一些数据,其中“phone_number”列的格式如下所示。如何只提取数据中与区号和后续电话号码对应的数字,并且仅提取国家代码为+1的地方?

phone_number
+1 414-935-5896
+1 (408) 832-3423
+91 90353 45657

我想要什么:

US_phone_number_only
4149355896
4088323423
NULL
sql text google-bigquery extract
1个回答
0
投票

您可以使用

REGEXP_REPLACE
从字符串列中仅提取数字,然后与
case expression
结合使用来确定哪些行需要处理。

with my_data as (
  select '+1 414-935-5896' as phone union all
  select '+1 (408) 832-3423' union all
  select '+91 90353 45657'
)
select 
 phone, 
 case
  when left(phone, 3) = '+1 ' then right(REGEXP_REPLACE(phone,'[^0-9]',''), 10) 
  --else null
 end as phone2
from my_data

输出:

电话 电话2
+1 414-935-5896 4149355896
+1 (408) 832-3423 4088323423
+91 90353 45657
© www.soinside.com 2019 - 2024. All rights reserved.