create or replace function fn_checkidcard(p_id_card in varchar2)
return varchar2 is
v_id_card varchar2(30);
v_sum number;
v_mod number;
v_checkcode char(11) := '10X98765432';
v_checkbit char(1);
v_checkbit1 char(1);
v_areacode varchar2(2000) := '11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91';
begin
if p_id_card is null then
v_id_card := '';
return v_id_card;
end if;
v_id_card := p_id_card;
--判斷位數
if length(p_id_card) <> 15 and length(p_id_card) <> 18 then
v_id_card := '';
--dbms_output.put_line('位數錯誤!');
return v_id_card;
end if;
--判斷地區代碼
if instr(v_areacode, substr(p_id_card, 1, 2)) = 0 then
v_id_card := '';
--dbms_output.put_line('地區代碼錯誤!');
return v_id_card;
end if;
--如果是15位
if length(p_id_card) = 15 then
--判斷第三位-第八位
for i in 3 .. 8 loop
if substr(p_id_card, i, 1) not between '0' and '9' then
v_id_card := '';
--dbms_output.put_line('第' || i || '位數字錯誤!');
return v_id_card;
end if;
end loop;
--判斷月份和日期
if substr(p_id_card, 9, 2) not in ('01',
&