若何優化SQL語句的心得淺談。本站提示廣大學習愛好者:(若何優化SQL語句的心得淺談)文章只能為提供參考,不一定能成為您想要的結果。以下是若何優化SQL語句的心得淺談正文
在開辟進程中,能夠會用到oracle sequence語句,本文以oracle sequence語句若何重置停止引見,須要的同伙可以參考下
Oracle重置sequence語句1
Sql代碼
DECLARE
n NUMBER(10 );
tsql VARCHAR2(100 );
p_seqName varchar2(20 );
BEGIN
p_seqName := 'SEQ_RUN_ID';
EXECUTE IMMEDIATE 'SELECT ' || p_seqName || '.NEXTVAL FROM dual ' INTO n;
n := - (n - 1);
tsql := 'alter sequence '|| p_seqName ||' increment by ' || n;
EXECUTE IMMEDIATE tsql;
EXECUTE IMMEDIATE 'SELECT ' || p_seqName || '.NEXTVAL FROM dual ' INTO n;
tsql := 'alter sequence '|| p_seqName ||' increment by 1' ;
EXECUTE IMMEDIATE tsql;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( SQLERRM);
END;
Oracle重置sequence語句2
Sql代碼
CREATE OR REPLACE PROCEDURE RESET_SEQUENCE(p_sSeqName IN VARCHAR2)
IS
n NUMBER(10 );
tsql VARCHAR2(100 );
BEGIN
EXECUTE IMMEDIATE 'SELECT ' || p_sSeqName || '.NEXTVAL FROM dual '
INTO n;
n := - (n - 1);
tsql := 'alter sequence ' || p_sSeqName || ' increment by ' || n;
EXECUTE IMMEDIATE tsql;
EXECUTE IMMEDIATE 'SELECT ' || p_sSeqName || '.NEXTVAL FROM dual '
INTO n;
tsql := 'alter sequence ' || p_sSeqName || ' increment by 1' ;
EXECUTE IMMEDIATE tsql;
EXCEPTION WHEN OTHERS THEN
NULL;
END RESET_SEQUENCE;