判斷輸入的身份證號碼中是否有除數字和'X'/'x'的函式

husthxd發表於2005-02-24

RT.


-- created by husthxd

create or replace function isGmsfhmWrong(vi_gmsfhm in char)
return varchar2
is
  vc_gmsfhm varchar2(20);
  vn_gmsfhm number;
begin 
  select replace(upper(vi_gmsfhm),'X','')
  into vc_gmsfhm
  from dual;
  begin
    select to_number(vc_gmsfhm)
    into vn_gmsfhm
    from dual;
    exception when others then
      return 'NOT VALID';
  end;
  return 'VALID';
  dbms_output.put_line(vc_gmsfhm);
end;
/

SQL> select isGmsfhmWrong('1352352324') from dual;

ISGMSFHMWRONG('1352352324')
--------------------------------------------------------------------------------

VALID

SQL> select isGmsfhmWrong('135w2352324') from dual;

ISGMSFHMWRONG('135W2352324')
--------------------------------------------------------------------------------

NOT VALID

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/6906/viewspace-21734/,如需轉載,請註明出處,否則將追究法律責任。

相關文章