如何测试所有数字 [英] How test for all digits
问题描述
我可以看到没有测试其参数为全部数字的函数,而且我没有简单的方法从翻译,替换等组成这样的函数。
我必须遗漏一些简单的东西吧?
Bob Stearns写道:
我看不到测试其参数为全部数字的函数,我看不出从翻译,替换等构成这样一个函数的简单方法。
我一定会遗漏一些简单的东西,对吗?
这样的事情可以解决问题:
CASE
当长度(更换(更换)(...( REPLACE(str,''0'',''''),'''',''''),...),
''9'',''' '))> 0
那么0
ELSE 1
END
或者您使用循环,SUBSTR和BETWEEN ...
-
Knut Stolze
DB2信息集成开发
IBM德国
CASE
WHEN LENGTH(RTRIM(翻译(test_str,'''',''0123456789'')))= 0那么
''所有数字''
ELSE''否''
结束
如果你感觉特别邪恶,你可以只是INTEGER()
参数和陷阱错误420.
B.
>
I can see no function which tests its argument to be all digits and I
see no easy way to compose such a function from translate, replace, etc.
I must be missing something simple, right?
Bob Stearns wrote:
I can see no function which tests its argument to be all digits and I
see no easy way to compose such a function from translate, replace, etc.
I must be missing something simple, right?
Something like this should do the trick:
CASE
WHEN LENGTH(REPLACE(REPLACE(...(REPLACE(str, ''0'', ''''), ''1'', ''''), ...),
''9'', '''')) > 0
THEN 0
ELSE 1
END
Or you use a loop, SUBSTR and BETWEEN...
--
Knut Stolze
DB2 Information Integration Development
IBM Germany
CASE
WHEN LENGTH(RTRIM(TRANSLATE(test_str, '''', ''0123456789''))) = 0 THEN
''All digits''
ELSE ''No''
END
If you are feeling particularly evil, you could just INTEGER() the
argument and trap error 420.
B.
这篇关于如何测试所有数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!