Oracle UDF Accumulation

Source: Internet
Author: User

Oracle custom function accumulation 1. Determine if it is a number www.2cto.com create or replace function IS_NUMBER (string VARCHAR2) return integer is begin if (LENGTH (TRIM (TRANSLATE (string, '+ -. 0123456789 ', '') is null) then return 1; else return 0; end if; end IS_NUMBER; 2. Determine whether the date is www.2cto.com create or replace function is_date (parmin VARCHAR2) return number is val DATE; BEGIN val: = TO_DATE (NVL (parmin, 'A '), 'yyyy-mm-dd hh24: mi: ss'); RETURN 1; exception when others then return 0; END; 3. Determine whether the ID card number is create or replace function IS_IDCard (p_IDcard varchar2) return booleanisIDcardlen integer default 0; begin IDcardlen: = Length (p_IDcard ); if (IDcardlen = 18 and IS_NUMBER (SubStr (p_IDcard, 1, IDcardlen-1) = 1 and IS_DATE (substr (p_IDcard, 7,8) = 1) or (IDcardlen = 15 and IS_NUMBER (SubStr (p_IDcard, 1, IDcardlen) = 1 and IS_DATE ('19' | subsTR (p_IDcard, 7, 6) = 1) then return TRUE; ELSE return FALSE; end if; end IS_IDCard; www.2cto.com 4. Get the age create or replace function get_age (workerid in varchar2) return varchar2isagevalue varchar2 (10) from the ID card number ); begin if (length (trim (workerid) = 18) then select (to_char (sysdate, 'yyyy')-to_char (substr (workerid, 7, 4) into agevalue from dual; else if (length (trim (workerid) = 15) then select (to_char (sysdate, 'yyyy')-to_char ('19' | substr (workerid, 7, 2 ))) into agevalue from dual; else agevalue: = '0'; end if; return agevalue; end; www.2cto.com 5. Obtain the Gender create or replace function get_Sex (p_IDCard varchar2) return varchar2isIDCardLen integer from the ID card number; begin IDCardLen: = length (p_IDCard); if IS_IDCARD (p_IDCard) = false then return null; end if; if IDCardLen = 18 and substr (p_IDCard, 17,1) in (, 9) then return ('male'); end if; if IDCardLen = 18 and substr (p_IDCard, 17,1) in (, 0) then return ('femal'); end if; if IDCardLen = 15 and substr (p_IDCard, 15, 1) in (, 9) then return ('male'); end if; if IDCardLen = 15 and substr (p_IDCard,) in (, 0) then return ('female '); end if; end get_Sex;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.