扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年10月1日
关键字: ORACLE
在本页阅读全文(共3页)
  if (len = 15) then
    -- 检查是否全为数字,否则转换操作会抛异常,导致程序崩溃,ascii('0') = 48, ascii('9') = '57'
    --for i in 1 .. 15 loop
    WHILE i <= 15 LOOP
        --ch := substr(id, i, 1); -- 非数字会报错
        c := ascii(substr(id, i, 1));
        if c < 48 or c > 57 then
            exit;
        end if;
        i := i + 1;
    end loop;
    IF i = 16 THEN
        trans := TRUE;
        ret := '19' || substr(id, 7, 2);
    END IF;
  end if;
  if (len = 18) then
    -- 2006-10-18 luocm
    -- 检查是否全为数字,否则转换操作会抛异常,导致程序崩溃,ascii('0') = 48, ascii('9') = '57'
    --for i in 1 .. 17 loop
    WHILE i <= 17 LOOP
        --ch := substr(id, i, 1); -- 非数字会报错
        c := ascii(substr(id, i, 1));
        if c < 48 or c > 57 then
            exit;
        end if;
        i := i + 1;
    end loop;
    c := ascii(substr(id, 18, 1));
    --if i <> 18 OR (c <> 88 AND c <> 120) OR c < 48 or c > 57 THEN -- 第18位为[0-9xX]
    if i = 18 AND (c = 88 OR c = 120 OR c >= 48 or c <= 57) THEN -- 第18位为[0-9xX]
        trans := TRUE;
        ret := substr(id, 7, 4);
    end if;
  end if;
  IF trans = FALSE THEN
      i := 1;
      WHILE i <= 8 LOOP
        c := ascii(substr(birthday, i, 1));
        if c < 48 or c > 57 then
            exit;
        end if;
        i := i + 1;
      end loop;
      IF i > 8 THEN
         yyyy := substr(ltrim(rtrim(birthday)), 1, 4);
         IF yyyy < 1900 OR yyyy > 2000 THEN
            ret := '';
         ELSE
            ret := yyyy;
         END IF;
      ELSE
         ret := yyyy;
      END IF;
  END IF;
  RETURN ret;
end f_extract_birthday;
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。