firebird - 仅从文本中选择数字

标签 firebird firebird2.5

任何人都可以帮助我如何只从文本中选择数字?

字符串可以是随机的,例如:

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/

相关文章:

sql - 在 firebird select 过程中显示给定月份和年份的所有日期

python - 如何为 Linux 和 Windows 分发带有嵌入式 Firebird SQL 的 Python 程序

stored-procedures - token 未知创建具有动态表名的存储过程

sql - 在 firebird 中使用 `LIKE :varname || ' %'` 上的索引

stored-procedures - Firebird SQL 游标重复最后一行

java - 嵌入式 Firebird 数据库和 Hibernate

sql - 在 Firebird 数据库中,如何使用授予选项向用户授予角色?

sql - Firebird 备份还原令人沮丧,有没有办法避免它?

firebird 2.5 用序号标记记录

firebird - 从执行 block 中选择?