Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 选择等于10位数的行_Sql_Regex_Postgresql_String Function - Fatal编程技术网

Sql 选择等于10位数的行

Sql 选择等于10位数的行,sql,regex,postgresql,string-function,Sql,Regex,Postgresql,String Function,我有一个名为idx的表,其中包含以下数据 id dex -- ------------ 1 Major 12354 2 CITY 541 DER 3 9987741221 4 7845741 5 789456 2121 如何选择仅包含数字的行,且应仅包含10个数字 预期产量为 id dex -- ----------- 3 9987741221 5 789456 2121 您可以使用正则表达式来匹配您的

我有一个名为idx的表,其中包含以下数据

id dex          
-- ------------ 
1  Major 12354  
2  CITY 541 DER 
3  9987741221   
4  7845741      
5  789456 2121  
如何选择仅包含数字的行,且应仅包含10个数字

预期产量为

id dex         
-- ----------- 
3  9987741221  
5  789456 2121 

您可以使用正则表达式来匹配您的条件
^[0-9]{10,10}$
,我使用了
replace()
函数来删除字符之间的空格(id 5中的索引)


^[0-9]{10,10}$

[0-9]
-获取数字

{10,10}$
-在您的情况下,所选字符串中的最大值和最小值都是
10


使用
char\u length()


{10,10}
可以替换为
{10}
select * 
from idx 
where replace(dex,' ','')~'^[0-9]{10,10}$' -- or '^[0-9]{10,}$'
select *
from idx 
where  dex~'^[0-9]' 
       and char_length(replace(dex,' ','')) = 10