Reset a sequence in Oracle

0 votes

In PostgreSQL I can do something like this:

ALTER SEQUENCE serial RESTART WITH 0;

Is there an Oracle equivalent?

Sep 24, 2018 in Database by darklord
• 6,170 points
441 views

1 answer to this question.

0 votes

You can try out something like this

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;
/
answered Sep 24, 2018 by DataKing99
• 8,130 points

Related Questions In Database

0 votes
1 answer

How do I reset a sequence in Oracle?

 If you want to set it to ...READ MORE

answered Sep 27 in Database by Omaiz
• 560 points
19 views
0 votes
1 answer

Find values in a comma separated string in a MySQL query

You can add commas to the left and ...READ MORE

answered Sep 10, 2018 in Database by darklord
• 6,170 points
2,684 views
0 votes
1 answer

How to do a batch insert in MySQL

You can try out the following query: INSERT ...READ MORE

answered Sep 10, 2018 in Database by darklord
• 6,170 points
378 views
0 votes
1 answer

ACID property in a database

ACID stands for Atomicity, Consistency, Isolation, Durability. It ...READ MORE

answered Oct 8, 2018 in Database by darklord
• 6,170 points
115 views
0 votes
1 answer

Install postgreSQL on Ubuntu

Installing PostgreSQL on Ubuntu is very simple, ...READ MORE

answered Mar 22 in Database by Nitesh
60 views
0 votes
1 answer

Access progrs prompt without switching accounts

Use the following to get the postgres prompt ...READ MORE

answered Mar 22 in Database by Mahi
41 views
0 votes
1 answer

Create new role - postgresql on ubuntu

If you are logged in as the postgres account, ...READ MORE

answered Mar 22 in Database by Danny
53 views
0 votes
1 answer
0 votes
1 answer

What is a Join in terms of database?

JOINS are used to combine rows from ...READ MORE

answered Nov 13, 2018 in Database by DataKing99
• 8,130 points
57 views
0 votes
1 answer

Indexes in Database

The index is a data structure that ...READ MORE

answered Aug 20, 2018 in Database by DataKing99
• 8,130 points
60 views