0% found this document useful (0 votes)
89 views

Setting Sequence Value To A Specific Number - Oracle Database

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

Setting Sequence Value To A Specific Number - Oracle Database

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3/2/2021 Setting Sequence Value to a Specific Number - Oracle Database

Más [email protected] Panel

Let's Develop in Oracle Search My Blog Sea

Setting Sequence Value to a Specific Number NEW ARTICLES

There are times when we want to reset sequence value or set sequence value to a specific number. I have created LISTAGG DISTINCT - Remove Duplicates -
Oracle 19c
following procedure to do that for me. It will set sequence to a specific number so that nextval will be the number
Redo Files, Redo Group and Redo Thread
which you want to be. This also handles the scenarios where sequence increment by is greater then one.
Oracle Database
Oracle Database 21c is here - Innovation
Release
create or replace procedure set_sequence_nextval
Generate Nested JSON using SQL in Oracl
(
Database
p_sequence in varchar2,
p_value in number default 1 Parse JSON data in Oracle Database using
) JSON_TABLE in SQL
is Automatic Indexing in Oracle 19c
l_current_value number; Autonomous Database
l_increment_by number; SQL to calculate PI using Nilakantha Series
begin
SQL Puzzle - Calendar of Current Year
execute immediate 'select ' || p_sequence || '.nextval from dual' AVG Aggregate Function and NULL in Orac
into l_current_value; Database
Oracle Aggregate Functions - Count Sum A
select increment_by Min Max
into l_increment_by
Constraint to Validate Data and Optimize th
from user_sequences
SQL - Manual Partition
where sequence_name = upper(p_sequence);

l_current_value := (l_current_value - p_value + l_increment_by) * -1;


ORACLE ERROR CODES
if (l_current_value <> 0) then ORA-00000 • ORA-00001 • ORA-00018
ORA-00020 • ORA-00027 • ORA-00054
execute immediate 'alter sequence ' || p_sequence || ' increment by ' || l_current_value || ' minvalue ORA-00257 • ORA-00600 • ORA-00604
ORA-00843 • ORA-00849 • ORA-00904
execute immediate 'select ' || p_sequence || '.nextval from dual'
ORA-00911 • ORA-00936 • ORA-00942
into l_current_value;
ORA-01031 • ORA-01034 • ORA-01017
execute immediate 'alter sequence ' || p_sequence || ' increment by ' || l_increment_by || ' minvalue ORA-01157 • ORA-01403 • ORA-01422
ORA-01436 • ORA-01439 • ORA-01460
end if; ORA-01476 • ORA-01489 • ORA-01555
ORA-01722 • ORA-01723 • ORA-01779
end set_sequence_nextval; ORA-01830 • ORA-01843 • ORA-02030
/ ORA-02041 • ORA-02303 • ORA-02438
ORA-03113 • ORA-03135 • ORA-04031
ORA-06502 • ORA-06512 • ORA-06530
ORA-06550 • ORA-08002 • ORA-12838
ORA-12154 • ORA-12514 • ORA-12545
ORA-12560 • ORA-16000 • ORA-23404
Demonstration 1: Set Next Value to 101 when sequence increment by is 1 ORA-27101 • ORA-28002 • ORA-30009
PLS-00172
SQL> create sequence test_sequence start with 1 increment by 1 nocache nocycle;
Sequence created.
POPULAR POSTS
SQL> exec set_sequence_nextval('test_sequence',101);
PL/SQL procedure successfully completed. ORA-01157: cannot identify/lock data file
string - see DBWR trace file
SQL> select test_sequence.nextval from dual; Efficient way to UPDATE bulk of records in
NEXTVAL Oracle Database
----------
Oracle: Getting Cumulative Sum (Running
101
Total) Using Analytical Functions
SQL> select increment_by from user_sequences where sequence_name = 'TEST_SEQUENCE'; Load CSV file in Oracle using PL/SQL
INCREMENT_BY Oracle: DBMS_STATS Gather Statistics of
------------ Schema, Tables, Indexes
1
ORA-03135: connection lost contact
One Time Immediate Job in Oracle
ORA-27101: shared memory realm does no
Demonstration 2: Set Next Value to 51 when sequence increment by is 5 exist
ORA-01489: result of string concatenation is
SQL> create sequence test_sequence start with 1 increment by 5 nocache nocycle; too long
Sequence created. ORA-12545: Connect failed because target
host or object does not exist
SQL> exec set_sequence_nextval('test_sequence',51);
PL/SQL procedure successfully completed.
LABELS
SQL> select test_sequence.nextval from dual;
NEXTVAL Oracle SQL (83) Oracle Tip
----------
51 (70) Ora-Codes (57) Optimizatio
(42) Oracle DBA (28) Oracle PL/SQ
SQL> select increment_by from user_sequences where sequence_name = 'TEST_SEQUENCE'; (26) Analytical Functions (14) Date/Time (1
INCREMENT_BY Oracle Puzzle (11) Connect By (10) Stri
------------ Aggregation (10) Oracle 12c (8) Regular Express
5 (7) Java Script (6) Subquery Factoring (5)

Related Posts: MY PROFILES

- Sequence Behavior with Multitable Insert All


- Auto Increment Column Performance Enhancement with each Oracle Version

nimishgarg.blogspot.com/2014/09/setting-sequence-value-to-specific.html 1/2
3/2/2021 Setting Sequence Value to a Specific Number - Oracle Database
- Oracle Auto Increment Column - Sequence as Default Value
- Sequence: NEXTVAL, CURRVAL and SESSION
- USER_SEQUENCES.LAST_NUMBER AND SEQUENCE CACHE

TOTAL PAGEVIEWS
Labels: Oracle PL/SQL
3 6 1 5 3 8 7
1 comment: FOLLOWERS

Seguidores (276) Siguiente


Anonymous August 8, 2018 at 7:39 PM
Yoսr style іs so unique compared to otһеr
people Ӏ'ѵе read stuff from. Tһank y᧐u for posting ᴡhen you havе tһe opportunity,
Guess Ι'll just bookmark thi page.
Reply

Enter your comment...

Seguir

Comment as: cperez@kione Sign out


BLOG ARCHIVE


► 2021 (2)
Publish Preview Notify me ►
► 2020 (8)

► 2019 (15)
Subscribe to: Post Comments (Atom) ►
► 2018 (15)

► 2017 (12)

► 2016 (17)

► 2015 (20)

▼ 2014 (28)

► December (1)

► November (1)

► October (4)

▼ September (2)
Difference Between Cursor And Ref Curs
Setting Sequence Value to a Specific
Number


► August (1)

► July (3)

► June (2)

► May (3)

► April (4)

► March (2)

► February (3)

► January (2)


► 2013 (33)

► 2012 (25)

► 2011 (23)

► 2010 (65)

► 2009 (39)

Copyright © 2009-2016 | Nimish Garg | All rights reserved.. Powered by Blogger.

nimishgarg.blogspot.com/2014/09/setting-sequence-value-to-specific.html 2/2

You might also like