xQb*_*ert 26
CASE
WHEN LENGTH(RTRIM(TRANSLATE(test_str, '*', ' 0123456789'))) = 0
THEN 'All digits'
ELSE 'No'
END
Run Code Online (Sandbox Code Playgroud)
Esp*_*o57 10
如果您的 db2 版本可以使用 regexp_like 您可以这样做:
带“.”的数字 作为十进制符号:
select * from yourtable
where REGEXP_LIKE(trim(yourzone) , '^\d+(\.\d*)?$')
Run Code Online (Sandbox Code Playgroud)
以“,”作为小数点的数字:
select * from yourtable
where REGEXP_LIKE(trim(yourzone) , '^\d+(\,\d*)?$')
Run Code Online (Sandbox Code Playgroud)
不带小数符号的数字(仅整数,您的要求)
select * from yourtable
where REGEXP_LIKE(trim(yourzone) , '^\d+$')
Run Code Online (Sandbox Code Playgroud)
有很多方法。看一下仅使用两个函数的解决方案:
CASE
WHEN REPLACE(TRANSLATE(test_str, '0','123456789','0'),'0','') = ''
THEN 'All digits'
ELSE 'Not all digits'
END
Run Code Online (Sandbox Code Playgroud)
一般来说 - 功能更少 - 性能更好:)