如何检查逗号分隔的字符串值中的所有值是否为数字? [英] How to check if all values in a comma separated string values are numeric?

查看:78
本文介绍了如何检查逗号分隔的字符串值中的所有值是否为数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查逗号分隔的字符串

I want to check if comma separated string

'822632,822633,822634,822635,827402,827403,827404,827405'



有所有数值?



我尝试过ISNUMERIC但感觉不舒服




have all numeric values??

I tried ISNUMERIC but something feels off

select ISNUMERIC('822632,822633,822634,822635,827402,827403,827404,827405') -- 0
Select ISNUMERIC('822632,822633') --1
Select ISNUMERIC('8226326125163143146341') --1
Select ISNUMERIC('822632,822633,822') -- 1
Select ISNUMERIC('822632,822633,8243') --0
Select ISNUMERIC('822632323232233,822633') -- 0
Select ISNUMERIC('8226323,8226335612') --0







还有什么其他选择以及为什么选择ISNUMERIC不管用 正确



谢谢




What are other options and why ISNUMERIC is not working properly

Thanks

推荐答案

你可以使用PATINDEX:



You can use PATINDEX:

select PATINDEX('%[^0-9,]%', '822632,822633,822634,822635,827402,827403,827404,827405') -- 0
Select  PATINDEX('%[^0-9,]%', '822632,822633') --0
Select  PATINDEX('%[^0-9,]%', '8226326125163143146341') --0
Select  PATINDEX('%[^0-9,]%', '822632,822633,822') -- 0
Select  PATINDEX('%[^0-9,]%', '822632,822633,8243') --0
Select  PATINDEX('%[^0-9,]%', '822632323232233,822633') -- 0
Select  PATINDEX('%[^0-9,]%', '8226323,8226335612') --0
Select  PATINDEX('%[^0-9,]%', '822632,a822633') --8
Select  PATINDEX('%[^0-9,]%', 'a822632,a822633') --1





模式[0-9,]查找1到9中的任何一个或逗号,[^ 0-9,]查找其他所有内容。如果找到任何其他字符,它将返回索引> 0,否则为零



The pattern [0-9,] looks for any of 1 to 9 or comma, [^0-9,] looks for everything else. If it finds any other char it will return index>0, otherwise zero


您可以先尝试替换逗号,然后再执行ISNUMERIC。

这样的东西:

You could try and replace the comma first and then do ISNUMERIC.
Something like this:
select ISNUMERIC(replace('8226323,8226335612',',','')) AmINumeric



不确定它是否适用于真正非常大的数字。


Not sure if it will work on really really very large numbers though.


这篇关于如何检查逗号分隔的字符串值中的所有值是否为数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆