我有一个需要将所有SQL Server存储过程转换为HANA存储过程的要求。我在T-SQL中遇到过函数ISNUMERIC,但在HANA中却没有得到与之等效的函数。
在网上搜索后,我发现HANA尚未内置ISNUMERIC等效功能。然后,我尝试编写自己的函数来实现此目标,并且在那里我坚持了错误处理和正则表达式限制。
我的HANA版本是70。
SAP HANA没有附带ISNUMERIC()
功能。但是,已在SCN上多次询问并回答了此问题:例如http://scn.sap.com/thread/3449615
或我过去的方法:http : //scn.sap.com/thread/3638673
drop function isnumeric;
create function isNumeric( IN checkString NVARCHAR(64))
returns isNumeric integer
language SQLSCRIPT as
begin
declare tmp_string nvarchar(64) := :checkString;
declare empty_string nvarchar(1) :='';
/* replace all numbers with the empty string */
tmp_string := replace (:tmp_string, '1', :empty_string);
tmp_string := replace (:tmp_string, '2', :empty_string);
tmp_string := replace (:tmp_string, '3', :empty_string);
tmp_string := replace (:tmp_string, '4', :empty_string);
tmp_string := replace (:tmp_string, '5', :empty_string);
tmp_string := replace (:tmp_string, '6', :empty_string);
tmp_string := replace (:tmp_string, '7', :empty_string);
tmp_string := replace (:tmp_string, '8', :empty_string);
tmp_string := replace (:tmp_string, '9', :empty_string);
tmp_string := replace (:tmp_string, '0', :empty_string);
/*if the remaining string is not empty, it must contain non-number characters */
if length(:tmp_string)>0 then
isNumeric := 0;
else
isNumeric := 1;
end if;
end;
测试结果显示:使用数据as(从虚拟联合中选择“ 1blablupp”作为VAL,从虚拟联合中选择“ 1234”作为VAL,全部从虚拟联合中选择“ bla123”作为val)
select val, isNumeric(val) from data
VAL ISNUMERIC(VAL)
1blablupp 0
1234 1
bla123 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句