The sequence is cleared in the early morning, so that the sequence starts from 1 every day.

Source: Internet
Author: User


The sequence is cleared early every morning, so that the sequence starts from 1 every day. job: www.2cto.com SQL code begin sys. dbms_job.submit (job =>: job, what => 'clearseq (''seq _ SN_ID ''); ', next_date => to_date ('16-10-2012 18:37:20 ', 'dd-mm-yyyy hh24: mi: ss'), interval => 'trunc (SYSDATE) + 1/24 + 1'); commit; end;/Stored Procedure Delete sequence, create a new sequence, but note that this method cannot be used for removing sequence from a stored procedure, because after a new sequence is deleted, the stored procedure must be re-compiled before it can be used. This method uses the SQL code create or replace procedure ClearSeq (seqName in varchar) as n_count number (8); v_ SQL varchar (500); v_code NUMBER; v_errm VARCHAR2 (64); -- mahongmin begin select count (1) into n_count from user_sequences t -- where t. sequence_name = 'seq _ SN_ID '; where t. sequence_name = seqName; if n_count> 0 then execute immediate 'drop sequence '| seqName; end if; v_ SQL: = 'create sequence '| seqName | 'minvalue 1 maxvalue 99999999 start with 1 increment by 1 NOCYCLE cache 20'; execute immediate v_ SQL; exception when others then v_code: = SQLCODE; v_errm: = SUBSTR (SQLERRM, 1, 64); DBMS_OUTPUT.PUT_LINE ('error code when sequence is reset '| v_code |': '| v_errm); end;
 

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.