任何人都可以帮助我如何只从文本中选择数字?
字符串可以是随机的,例如:
ABCD123DEF -> Result must be 123
393SEA981F -> Result must be 393981
谢谢!Firebird 版本是 2.5
最佳答案
首先想到的是:
使用存储过程作为:
SET TERM ^ ;
create or alter procedure GET_DIGIT_ONLY (
IPARAM varchar(32))
returns (
OPARAM varchar(32))
as
declare variable I integer;
begin
oparam = '';
i = 1;
while (i <= char_length(:iparam)) do
begin
if (substring(:iparam from i for 1) similar to '[0123456789]') then
oparam = :oparam || (substring(:iparam from i for 1));
i = :i + 1;
end
suspend;
end^
SET TERM ; ^
使用方法:
execute procedure get_digit_only :input_param
returning_values :output_param
或
select get_digit_only.oparam from get_digit_only ('393SEA981F')
关于firebird - 仅从文本中选择数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42549779/