手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 11g Release 1 (11.1) 函数为表的某个字段进行字母数字组合编码

[日期:2012-06-24] 来源:Linux社区  作者:liuning8023 [字体:大 中 小]

字母数字组合进位 F_Comm_NumLetterCarry

create or replace function F_Comm_NumletterCarry(v_char in varchar2)
  return varchar2 is
  Result           varchar2(1);
  const_num_letter char_table;
  i                number;
begin
  const_num_letter := new char_table('0',
                                     '1',
                                     '2',
                                     '3',
                                     '4',
                                     '5',
                                     '6',
                                     '7',
                                     '8',
                                     '9',
                                     'A',
                                     'B',
                                     'C',
                                     'D',
                                     'E',
                                     'F',
                                     'G',
                                     'H',
                                     'I',
                                     'J',
                                     'K',
                                     'L',
                                     'M',
                                     'N',
                                     'O',
                                     'P',
                                     'Q',
                                     'R',
                                     'S',
                                     'T',
                                     'U',
                                     'V',
                                     'W',
                                     'X',
                                     'Y',
                                     'Z');
  i                := 1;
 
  while i <= const_num_letter.count loop
    if const_num_letter(i) = v_char then
      exit;
    end if;
    i := i + 1;
  end loop;
 
  if i = const_num_letter.count then
    Result := const_num_letter(1);
  elsif i > const_num_letter.count then
    Result := '';
  else
    Result := const_num_letter(i + 1);
  end if;
  return Result;
end F_Comm_NumletterCarry;
/

字母数字组合自增 F_Comm_IncreaseNumLetter

create or replace function F_Comm_IncreaseNumLetter(code in varchar2)
  return varchar2 is
  Result       varchar2(100);
  newCode      varchar2(100);
  v_char_table char_table;
  v_char       varchar2(1);
  isCarry      number;
  i            number;
begin
  v_char_table := f_comm_splitstr(upper(code));
  i            := v_char_table.count;
  newCode      := '';
 
  while i >= 1 loop
    if i = v_char_table.count then
      -- 是否进位      
      if v_char_table(i) = 'Z' then
        isCarry := 1;
      else
        isCarry := 0;
      end if;
      -- 加 1    
      v_char := f_comm_numlettercarry(v_char_table(i));
    else
      if isCarry = 1 then
        v_char := f_comm_numlettercarry(v_char_table(i));
      else
        v_char := v_char_table(i);
      end if;
      -- 是否再进位      
      if v_char_table(i) = 'Z' then
        if isCarry = 1 then
          isCarry := 1;
        end if;
      else
        isCarry := 0;
      end if;
    end if;
    newCode := v_char || newCode;
    i       := i - 1;
  end loop;
  if isCarry = 1 then
    newCode := isCarry || newCode;
  end if;
  Result := newCode;
  return Result;
end F_Comm_IncreaseNumLetter;
/
linux
相关资讯       Oracle存储过程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款