Oracle functions "Automatically generate order Numbers"

Source: Internet
Author: User

1 Create or Replace functionGet_request_codereturn varchar2  as2 3         --function: Automatic generation of order numbers4V_mca_no Mcode_apply_01.mca_no%TYPE;5 6        CURSORGet_max_mca_no is   7               SELECT Max(Substr (Mca_no, One,1))--the largest number detected, intercept the last one, such as: 1, 2...N8                frommcode_apply_019               WHERESUBSTR (Mca_no,3,8)=To_char (Sysdate,'YYYYMMDD');--intercept number, such as: 20170422Ten  OneV_requestcodeVARCHAR2(3); A  -   BEGIN -        OPENGet_max_mca_no; the        FETCHGet_max_mca_no intoV_requestcode; -        CLOSEGet_max_mca_no; -  -   IFV_requestcode is NULL  Then +V_requestcode:=NVL (V_requestcode,0);--NVL () function: When V_requestcode is null, take 0 as the value -   END IF; +  AV_requestcode:=Lpad (V_requestcode+ 1,3,'0');--add 1 to the value that is intercepted in the cursor, and then fill 0 to the left, generating a 001...00n ordinal; Lpad () function: padding left at  -V_mca_no:= 'MA' ||To_char (Sysdate,'YYYYMMDD')||V_requestcode;--the resulting application number (eg: ma20170422001;ma20170422002; ma2017042200n) -  -    -   RETURN '0~,'||V_mca_no; -  in END;

function substr (), Detailed: http://www.cnblogs.com/dshore123/p/7805050.html

Oracle functions "Automatically generate order Numbers"

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.