Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92488282
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: Oracle

2008-04-30 21:29:17

--从原有的15位身份证号转换成新的18位(附PASCAL代码)
function IDENTITYCODE15TO18(p_OldID varchar2) return varchar2 is
-- Author : XJG()
-- Created : 2003-11-03 18:38:56
-- Purpose : 从原有的15位身份证号转换成新的18位
type TIArray is table of integer;
type TCArray is table of char(1);
Result varchar2(18);
W TIArray;
A TCArray;
S integer;
begin
if Length(p_OldID) <> 15 then
raise_application_error(-20999, '不是旧15位身份证号');
end if;
W := TIArray(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
A := TCArray('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
Result := SubStr(p_OldID, 1, 6) || '19' || SubStr(p_OldID, 7, 9);

S := 0;
begin
for i in 1 .. 17 loop
S := S + to_number(SubStr(Result, i, 1)) * W(i);
end loop;
exception
when others then
return '';
end;
S := S mod 11;
Result := Result || A(s + 1);

return(Result);
end IDENTITYCODE15TO18;

 

原文:http://java2006.blog.ccidnet.com/blog-htm-itemid-90213-do-showone-type-blog-uid-36641.html

阅读(655) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~