How can I reset a sequence in Oracle?

1145765 pts.
Tags:
Database
Oracle
PostgreSQL
Does anyone know how to reset a sequence in Oracle? I know that in PostgreSQL, I used this:
ALTER SEQUENCE serial RESTART WITH 0;
Is there anything like this in Oracle?
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • AshishSingh10
    Hi,

    The below mentioned code can be utilized: -

    create or replace
    procedure reset_seq( p_seq_name in varchar2 )
    is
        l_val number;
    begin
        execute immediate
        'select ' || p_seq_name || '.nextval from dual' INTO l_val;
    
        execute immediate
        'alter sequence ' || p_seq_name || ' increment by -' || l_val || 
                                                              ' minvalue 0';
    
        execute immediate
        'select ' || p_seq_name || '.nextval from dual' INTO l_val;
    
        execute immediate
        'alter sequence ' || p_seq_name || ' increment by 1 minvalue 0';
    end;
    /

    Thanks and regards
    Ashish@S
    1,330 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: