存储过程实现判断字符串是否是整数

项目中要用到存储过程,学习一下。下面是自己写的一个存储过程,希望大家能提些意见,谢谢!

create or replace package body common_function is
  procedure is_number(num in varchar2, isFlag out boolean) is
    head_num varchar2(1);
    last_num varchar2(1);
    idx int;
  begin
    head_num := substr(num, 1, 1);--第一个字符,第一个字符判断是否等于‘0’或则等于‘.’,如果等于则不是数字字符串
    last_num := substr(num, -1);--最后一个字符,判断是否等于‘.’,如果等于则不是数字字符串
    idx:=instr(num,'.',1,2);--查找出num字符串中第二个‘.’字符的位置,如果存在则不是数字字符串
    if translate(num, '1234567890.' || num, '1234567890.') = num then--对num字符串做过滤,非'1234567890.'字符就会被删除掉,
                                                                     --判断过滤后的字符串是否与原字符串相等
      if head_num = '0' or head_num = '.' or last_num = '.' or idx>1 then
        isFlag := false;
      else
          isFlag := true;
      end if;
    else
      isFlag := false;
    end if;
  end is_number;
end common_function;

猜你喜欢

转载自zhang489526-126-com.iteye.com/blog/1583175