Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 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 Bookmark and Share

<< 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 IMMEDIATESELECT||p_Name
||.NEXTVAL FROM DUAL’ INTO v_num;
EXECUTE IMMEDIATEALTER SEQUENCE ‘
||p_Name
||’ INCREMENT BY||(p_val - v_num - 1)
||’ MINVALUE 1&#8242;;
EXECUTE IMMEDIATESELECT||p_Name
||.NEXTVAL FROM DUAL’ INTO v_num;
EXECUTE IMMEDIATEALTER 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. 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 145 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?