Quick Search:
 
 Oracle PL/SQL: SEQUENCE: Reset a sequence to a predefined number Jump to:  
Category: >> Oracle PL/SQL >> SEQUENCE: Reset a sequence to a predefined number  

<< lastnext >>

Snippet Name: SEQUENCE: Reset a sequence to a predefined number

Description: A small PL/SQL procedure that resets the sequence to a predefined number. Note that the sequence is NOT being dropped or re-initialized to zero.

Also see:
» SEQUENCE: Demo code and Examples
» SEQUENCE: Find sequence MAX value
» SEQUENCE: get sequence value into vari...
» SEQUENCE: Autonumber into two tables
» SEQUENCE: Create sequence demo

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 06th, 2009

CREATE OR REPLACE PROCEDURE Set_seq_To
(p_Name  IN VARCHAR2,
p_val   IN NUMBER)
IS
v_num  NUMBER;
BEGIN
EXECUTE IMMEDIATE ‘SELECT ‘
||p_Name
||’.NEXTVAL FROM DUAL’ INTO v_num;
EXECUTE IMMEDIATE ‘ALTER SEQUENCE ‘
||p_Name
||’ INCREMENT BY ‘
||(p_val - v_num - 1)
||’ MINVALUE 1&#8242;;
EXECUTE IMMEDIATE ‘SELECT ‘
||p_Name
||’.NEXTVAL FROM DUAL’ INTO v_num;
EXECUTE IMMEDIATE ‘ALTER SEQUENCE ‘
||p_Name
||’ INCREMENT BY 1 ‘;
DBMS_OUTPUT.Put_Line(’Sequence ‘
||p_Name
||’ IS NOW AT ‘
||p_val);
END;
 
-- p_Name is the name of the sequence
-- p_val is the number to reset it to. 


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org