首页 > 解决方案 > 查找所有开头包含“+7”的数字

问题描述

我需要找到'+7'开头包含的所有数字。

我想过,~但它对我没有用。

SELECT * 
from ds_phone 
where number ~ '+7 \d'

标签: sqlpostgresql

解决方案


一种选择是使用substring()函数:

select * 
  from ds_phone 
 where substring(number,1,2)='+7'

因为number是字母数字列,所以不需要强制转换。


推荐阅读