Solved

Oracle Sequence

Posted on 2014-07-31
9
312 Views
Last Modified: 2014-08-05
I have a table that Im working with and it has a sequence to get the next value for the ID field on the table. The ID field is NOT a primary key. I want to change it but for now I see it has dependencies and I dont want to mess anything up. I noticed that when I did an Insert it is inserting a duplicate value of 3 into the this field. I opened the Sequence and the Last Number is now 3 so I understand how this happened. My question is, can I have the LastNumber look at my ID field and determine the next number? Or does this have to be a primary key in order for that to happen?

Thanks for any help!!
0
Comment
Question by:jknj72
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 40231906
Assuming you are using actual sequences,  they have nothing to do with primary keys (except that they are frequently used for setting their values).

The same sequence could be used for multiple tables, and sequences can be reset by dropping and recreating.

This site describes how the value stored in a sequence can be changed:

http://www.gokhanatil.com/2011/01/how-to-set-current-value-of-a-sequence-without-droppingrecreating.html
0
 

Accepted Solution

by:
jknj72 earned 0 total points
ID: 40231921
I managed to go around it for now. And what do you mean by "Assuming you are using actual sequences"?
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 40231935
I meant the actual objects called SEQUENCE and created by

CREATE SEQUENCE sequence_name;

statements (rather than just a logical sequence of numbers).
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:jknj72
ID: 40231966
well to answer your question I am using Actual Sequences
0
 
LVL 34

Expert Comment

by:johnsone
ID: 40231981
Also, be aware that a sequence can get to its maximum value and then start again at the minimum value.  This is controlled by specifying CYCLE or NOCYCLE when creating the sequence.
0
 
LVL 34

Expert Comment

by:johnsone
ID: 40231984
FYI,

MAX + 1 will not work if multiple users insert records at the same time.  You will most likely see duplicate values.
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 40231990
As johnsone said, that is a big no-no.
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40232804
You are making a mistake, listen to johnsone or .... SUFFER THE CONSEQUENCES.
0
 

Author Closing Comment

by:jknj72
ID: 40240748
FYI, I simply did a MAX + 1 on the ID field and used that for my next value. I know, not the ideal way to do things but until I can decipher whether changing the table and putting a primary key on it, possibly with a trigger for incrementing, then this will have to do...
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now