The document number generated by the oracle trigger and the oracle trigger

Source: Internet
Author: User

The document number generated by the oracle trigger and the oracle trigger
Create or replace trigger TRG_KC_SPRK_ I
Before insert on KC_SPRK
FOR EACH ROW
DECLARE
VSCBH varchar2 (40 );
ICount NUMBER;
IFor number;
BEGIN
Select t. bhqz into vSCBH from xt_djbhgz t where t.gz id = 8; -- obtain a field of another table as the prefix, or assign a value directly to the field: vSCBH: = 'gxcb _'
Select count (1) + 1 INTO iCount from KC_SPRK j where j. xzsj> = trunc (sysdate, 'mm'); -- obtain the total number of tables in this table + 1 and assign the value to iCount.
VSCBH: = vSCBH | to_char (sysdate, 'yyyymm'); -- prefix + date and year
FOR iFor IN 1 .. 5-LENGTH (iCount) LOOP
VSCBH: = vSCBH | '0 ';
End loop;
: New. RK_DJH: = vSCBH | iCount;

END TRG_KC_SPRK_ I;



Result: GXCB_20141100001 GXCB_20141100002 GXCB_20141100003



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.