Auto increment sequence problem

Hi,
Is there any particular thing about 21st record because, when i insert data into same or different table, records start from 21 instead of 1 or where it was finished before.
Example : I leave a table with 3 records. Come back, I insert data into same table then, auto increment starts from 21 not the 4!!!
Thanks
CREATE SEQUENCE FRANC_AUTOINC_SEQ
START WITH 1
INCREMENT BY 1
NOMAXVALUE;
CREATE TRIGGER FRANC_AUTOINC_TRG
BEFORE INSERT ON FRANCHISE
FOR EACH ROW
BEGIN
SELECT FRANC_AUTOINC_SEQ.NEXTVAL INTO :NEW.FRANCHISEID FROM DUAL;
END;

Hi,
There's no need to do anything.
If you want fewer numbers to be discarded in the future, you can make the cache size smaller, or remove it entirely, as in:
CREATE SEQUENCE FRANC_AUTOINC_SEQ
START WITH 1
INCREMENT BY 1
NOMAXVALUE
NOCACHE;This may mean slightly less efficiency, since (to use my earlier analogy) you have to go to the number store and buy a new box every time you need a number, rather than going to the store once and not having to go back again until you've used up the box of twenty numbers. If you rarely use more than one new number in a session, the loss in efficiency will be insignificant.
Regardless of the caching, if only one session is using the sequence, you will get consecutive numbers in that session. If NOCACHE is in effect, and you are the only person using the sequence, you will get consecutive numbers even if work over multiple sessions.
Ending the session is what causes the cached numbrs to be discarded. Shutting down the database implies ending all sessions, but otherwise has nothing to do with the sequence.
Message was edited by:
Frank Kulash

Similar Messages

  • Auto increment sequence

    Can I do something like auto increment sequence in planning so that whenever a user adds new asset it takes a number from this sequence.
    Thanks,
    foksh

    Hi,
    Create a member called Counter in Accounts.
    Increment the value everytime you add an asset and assign the value after update to asset number:
    -Make sure member combination for the Counter values is fixed to one combination only
    Counter->BegBalance->NoYear->(one member from all dimensions)=Counter->BegBalance->NoYear->(one member from all dimensions)+1;
    "Asset Number" = Counter->BegBalance->NoYear->(one member from all dimensions);
    Cheers,
    Alp

  • Auto Increment Sequence Custom Field

    Hi All,
    I was wondering if it is possible
    to have a custom field defined as an auto incrementing sequence number?  E.g. Let’s say I go in and create a project for the first time, this field will show the value 1.  The next project I go to create, the field shows the value 2 etc. etc. 
    If possible, how can this be implemented using customization?  Can it be done in Project Online?  Any help would be greatly appreciated.  thank you!

    Hi JSimoni1,
    You can generate a project unique ID using a webpart, even with Project Online.
    Please find below the procedure in EpmExpert blog:
    http://epmxperts.wordpress.com/2012/05/21/generate-unique-id-for-project-using-a-webpart/
    Note that the code might need some adjustments to stick to your business need.
    Hope this helps,
    Guillaume Rouyre, MBA, MCP, MCTS |

  • Create Auto increment sequence number for list view report

    Hi All,
              Am using BAM 11.1.1.6 version, Have updating list report & wants to create auto increment sequence number at report level. Is it possible to create column at run time in BAM reports.
    Please help.
    Thanks.

    Hi All,
              Am using BAM 11.1.1.6 version, Have updating list report & wants to create auto increment sequence number at report level. Is it possible to create column at run time in BAM reports.
    Please help.
    Thanks.

  • Auto Increment Field / Sequence - How?

    Am I missing something here - is there no build in support to tie a datatables auto incriment field to a sequence so that it will be automatically retrieved on a update command?
    I have a table that has a field (RECORD_ID) that gets it's value from a Sequence (RECORD_IDSEQ).
    I am retrieving a dataset and setting the RECORD_ID field to autoincrement, setting the seed & step to -1. Then I am adding some records & I see the autoincrement field i working correctly. UNFORTUNATELY, I still have to iterate through the table before I call an update in order to insert (from another function) the RECORD_IDSEQ.NEXTVAL value into the RECORD_ID column.
    Surely I am missing something. It sure seems simple enough to have a property of the autoincrement field/command builder that relates to the SEQUENCE name so that the update method generates the RECORD_IDSEQ.NEXTVAL automagically.
    Can anyone shed any light on this for me?
    Thanks!

    Bob,
    Currently, there's no built-in "link" between the .NET DataTable's auto-increment field and the Oracle sequence.
    Therefore, you will need to execute a custom update command or a custom insert command which uses the RECORD_IDSEQ.NEXTVAL for the RECORD_ID column (rather than the auto-generated SQL via the CommandBuilder).
    Furthermore, in your custom SQL you can have a RETURNING clause which returns the RECORD_ID column value to populate back into the DataTable so that the sequence values in the Database is in sync with those in the DataTable.
    We'll consider providing a way to "link" the DataTable auto-increment column to an Oracle sequence in a future release.

  • Problems with EJB 2.0 et Auto Increment PK

    How to implement EJB 2.0 Entity bean for auto increment DB filed, let's say I have table adress(ID, city,state), ID is auto-increment PK, I have ejbCreate(city,state) and it generates exception (Caused by: SQL Exception: Attempt to modify an autoincrement column 'ID'. ) even if i set ID to null in ejbCreate.
    DB is Cloudscape 51, app. server is Websphere 5.1

    Okay, maybe getID() makes sense if needed :) But I
    thought I read
    somewhere else that in case of autoincrement, the ID
    field has to be
    read-only... Am I wrong here? If I am, I beg your
    pardon for giving a wrong
    answer, Matthieu :)How does the container tell your entity bean what it's ID is when it gets created?
    You start off with an entity bean which has not been persisted in the database, so your ID field is NULL or zero.
    You say: "Hey container, this bean instance you gave me, can you make sure that it is persisted in your data store?"
    The container goes and creates a new row, get's a new ID for the row, populates the row with the data from your bean and sets the ID property in your bean instance to the id of the newly created row and says "OK, I've done that, here's your bean back"
    Now that was the simple answer why... there is a more complex answer which is that the container will only ever create a fixed number of your entity beans in RAM (it's configured in the XML deployment descriptor, let's pretend it's 2)
    You say: "I want a new bean"
    Container gives you bean #1
    Joe says: "I want a new bean
    Container gives joe bean #2
    You say: "I want to compare bean #1 with another bean which is in the database"
    The container looks at Joe's bean and says... that hasn't been used recently, serializes the bean saves the serialized form in temporary storage and gives you bean #2.
    You say: "I'm done with those bean #1"
    Joe says: "Where's me bean?"
    The container reads the serialized form from temporary storage and puts it into bean #1 and gives it to Joe
    You need a setID because the container needs setID to function.

  • Auto increment of month problem

    public void AssignRTA(String date){
    String[] StartDate = date.split("/");
    GregorianCalendar calStart = new GregorianCalendar(Integer.parseInt(StartDate[2]), Integer.parseInt(StartDate[0]) , Integer.parseInt(StartDate[1]));
    System.out.println("Date: " + dfmt.format(calStart.getTime()));
    Hi, I passed in a String contain "2/7/2003" (mm/dd/yyyy). Split it and StartDate[0] = Month, StartDate[1]= Day, StartDate[2]= Year.
    When I do it this way, the month will auto increment by 1.
    The printout will be 3/7/20003. Why is that so?
    Please advise. Thanks

    Sorry for the triple post.
    If you want to convert your date string to a Date object, use:Date yourDate = null;
    try {
       SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
       yourDate = formatter.parse("05/06/2000");
    } catch (ParseException e) { }tajenkins

  • Auto-increment  identity column through procedure in oracle 10g on windows

    Hi,
    I need identity primary key which should be auto increment before while inserting data into table.
    for this i had use sequence and then trigger to increment it.
    but now i need to increment it in Procedure, while my procedure is having code to insert data in same table which has primary key

    Hi,
    SNEHA RK wrote:
    Hi,
    I need identity primary key which should be auto increment before while inserting data into table.
    for this i had use sequence and then trigger to increment it.Right. Some database products have auto-increment columns, and they are really handy. Unfortunately, Oracle does not have auto-increment columns. A sequence is an auto-increment object, and it's the right way to automatically generate unique identifiers, but you need to explicity reference the sequence, either in you DML statements, or in a trigger that will automatically fire before a DML statement.
    but now i need to increment it in Procedure, while my procedure is having code to insert data in same table which has primary keyAre you saying that you need to increment the sequence, completely aside from INSERTing into the table?
    If so, just reference sequence_name.NEXTVAL wherever you want to. In PL/SQL, you can say
    SELECT  sequence_name.NEXTVAL
    INTO    number_variable
    FROM    dual;This works in any version of Oracle, but starting in Oracle 11, you also have the option of referencing te sequence without using dual, or any other table.
    I hope this answers your question.
    If not, post a complete script that people can run to re-create the problem and test their ideas.
    For example:
    -- Here are the table and the seqauence that I created:
    CREATE TABLE table_x ...
    CREATE SEQUENCE ...
    -- Here is the BEFORE INSERT trigger I wrote:
    CREATE OR REPLACE TRIGGER ...
    -- The trigger works exactly how I want it to in statements like this:
    INSERT INTO table_x ...
    -- So there are no problems (that I know of) with anything up to this point.
    -- Now I want to use the same sequence to ...
    -- so that when I execute a statement like this
    -- then the next time  I add a new row to the orginal table, like this
    INSERT INTO table_x ...
    -- then the contents of table_x should be ... because ...

  • Not authorised to have auto increment trigger on server

    Hello all. I need a few triggers set up, I have no problems setting up sequences and "before insert" triggers on my home PC setup but on the live server where I study I do not have the authority.
    I got around this before by using Forms so I set the trigger at Form level.
    I am developing a DB system that will at some stage in the future use Forms, but for now it will use HTML forms via a web browser.
    I need to have the primary key for user accessible tables to be auto incremented (on the server where I study), but how can get around the authority issue ??
    Any ideas are extremely welcome !!

    Hello all - yeah I am on a course. I too have no idea why they will not allow the students to create triggers at table level.
    The 1st system I developed at home I had auto incremented primary keys. It was using Oracle Forms as the front end. Because I am the admin on my home setup I didn't have any problems.
    When I went to the course site to implement exactly what I had at home (which worked 100% properly) inserting data via the forms was not working. I had no idea why. the lecturer guy took a look at my code and told me its because of the trigger, I do not have authority to create triggers on the server.
    "create or replace trigger cust_trg
    before insert on customer
    for each row
    begin
    select cust_seq.nextval into :new.cust_id
    from dual;
    end;"
    The above code works fine on my home PC. I used Pre Insert triggers on the block on the Form instead to get around the problem (I presumed it was because they wanted us to learn Forms more thoroughly).
    This next project does not involve forms but they will not change my access rights so I don't have a clue as to how to get an auto incremented primary key whilst using a HTML form.
    Kevin

  • How to update a auto increment record

    Hi all,
    I just figured out a way to insert auto increment record, but there is still one problem to solve which is how to do the update of the auto increment record, because after I get the db record, I don't know if there is a way to get the associated sequence key with the record, I can't do the record update without knowing the primary key, ie the associated sequence key.
    Can you point me to a way to do updating?
    Regards,
    -Bruce

    You learn how to use JDBC.
    And then you learn how to use the SQL update statement.
    If you search in this forum for 'update' you will find examples.

  • DB Adapter - PostgreSQL - Primary key - auto increment handling

    Hi,
    I have to connect to a PostgreSQL DB. I have a table in which has a primary key called seq_id. This seq_id is being incremented using a sequence.
    I have to configure the DB adapter for this table. The problem is that while creating the adapter it does not allow me to deselect the primary key (seq_id). Because of this I have to supply a value for the seq_id while inseting the data using the adapter. But this defeats the purpose of sequence (auto increment).
    Is there a way to get around this and to avoid specifying the value for seq_id while using the DB Adapter and let it get inserted using the sequence of the DB?
    Thanks,
    Sanjay

    Hello ,
    you can see this thread :
    http://stackoverflow.com/questions/17012339/windows-azure-sql-database-identity-auto-increment-column-skips-values
    It's seems that SQL Server work with sequence and block 1000 values. In the cloud, your SQL Azure Database can be move from one server to an other or restarted and so a new sequence is used. That's why you jump from 4 to 1001.
    Regards

  • Primary key violation exception in auto increment column

    Hi All,
    I am facing one issue in Multi threaded environment.
    I am getting Primary key violation exception in auto increment column. I have a table and the primary key is the auto increment column, and I have a trigger which is populating this column.
    5 threads are running and inserting the data in the table and throwing Primary key violation exception randomly.
    create table example (
    id number not null,
    name varchar2(30)
    alter table example
    add constraint PK1example primary key (id);
    create sequence example_id_seq start with 1 increment by 1;
    create or replace trigger example_insert
    before insert on example
    for each row
    begin
    select example_id_seq.nextval into :new.id from dual;
    end;
    Any idea how to handle auto increment column(trigger) in Multi threaded environment??
    Thanks,

    user13566109 wrote:
    Thanks All,
    Problem was in approach; removed the trigger and placed a seq.nextval in insert query. It has resolved the issue.I very much suspect that that was not the issue.
    The trigger would execute for each insertion and the nextval would have been unique for each insertion (that's how sequences work in oracle), so that wouldn't have been causing duplicates.
    I suspect, more likely, that you had some other code somewhere that was using another sequence or some other method of generating the keys that was also inserting into the same table, so there was a conflict in the sources of the sequences being generated.
    The way you showed you had coded above, was a perfectly normal way to assign primary keys from a sequence, and is not a problem in a multi user/threaded environment.

  • Auto Increment column query

    I have a very simple table used for debugging:
    CREATE TABLE APPS.XX_DEBUG_TMP
      TEMP_VALUE  VARCHAR2(255 BYTE),
      TEMP_DATE   DATE
    )Then I can use it to store values as my pl/sql is processed - e.g.:
    INSERT INTO XX_DEBUG_TMP (TEMP_VALUE,TEMP_DATE) VALUES ('line 740 l_username value check:' || l_username,SYSDATE);  COMMIT;Trouble is that if a load of debug statements get processed with the same timestamp, I can't see which came first.
    Can I modify my table creation SQL to include an ID column which just increments for each row that is added to the table?
    I'm familiar with how to do it in MySQL (sorry - I know this is an Oracle forum - but am just putting this here to show what I mean):
    CREATE TABLE  `XX_DEBUG_TMP` (
    `TEMP_ID` MEDIUMINT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `TEMP_VALUE` VARCHAR( 255 ) NOT NULL ,
    `TEMP_DATE` DATETIME NOT NULL
    ) ENGINE = MYISAM ;Is it that simple with Oracle? Probably not!
    Any advice much appreciated.
    Thanks

    There is no auto increment column in Oracle. However, you can create a sequence.
    CREATE TABLE APPS.XX_DEBUG_TMP
      TEMP_ID     NUMBER NOT NULL PRIMARY KEY,
      TEMP_VALUE  VARCHAR2(255 BYTE),
      TEMP_DATE   DATE
    CREATE SEQUENCE APPS.XX_DEBUG_TMP_SEQ;Then in your insert statement do this:
    INSERT INTO XX_DEBUG_TMP (TEMP_ID,TEMP_VALUE,TEMP_DATE) VALUES (APPS.XX_DEBUG_TMP_SEQ.NEXTVAL,'line 740 l_username value check:' || l_username,SYSDATE);  Another possible solution to your problem would be to use a TIMESTAMP data type instead of a DATE data type. It has fractional second resolution (up to 9 places I believe).

  • JSP - Auto increment Oracle

    Hello,
    I've created some JSP pages with JDeveloper. When I want to create a new record in a table, then have I to fill in an unique ID for this record. Is it possible to get this field automatically filled in with an unique ID ? With Oracle, it's not possible to have an auto increment field. The solution I know, is to use a sequence and a trigger. But I doesn't want to use a trigger. Is there an other possibility ?
    Greetz, Joris

    It works! I've created a trigger to call the sequence to the primary key field and now it's populating that column properly.
    Just one more doubt about it: I've imported some data from my old Access 2003 database to the new XE database, but when I insert a new record in the table, my sequence doesn't retrieve the last value from the primary key column + 1, it's recording straight from position 1 forward. The sequence created automatically during db migration is this one:
    CREATE SEQUENCE "LOG_ID_LOG_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
    The problem with this sequence is that it doesn't see that I've migrated some data to this table before using it, so it's starting with value 1. How can I alter this sequence so it will always get the last (highest) value from my PK column + 1 before interting a new record to the table?
    Thanks again!
    Regards,
    Roger.

  • Auto Increment Feature

    Hello,
    Can anyone help me, I am trying to implement auto increment using sequences and triggers. But I seem to run into rough weather.
    CREATE TABLE "SCOTT"."tblCostCenterNum" (
         CostCenterNumID int NOT NULL ,
         CostNum int NOT NULL)
    TABLESPACE "ADMS_DEFAULT_TS"
    LOGGING;
    CREATE OR REPLACE TRIGGER "SCOTT"."TEST"
    BEFORE INSERT ON "SCOTT"."tblCostCenterNum"
    FOR EACH ROW
    BEGIN
    INSERT INTO "SCOTT"."tblCostCenterNum"(costcenternumid) ((select "SCOTT"."tblCostCenterNum_seq".nextval from dual));
    end;
    insert into "SCOTT"."tblCostCenterNum" (costnum) values (1);
    ERROR at line 1:
    ORA-04091: table SCOTT.tblCostCenterNum is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.TEST", line 2
    ORA-04088: error during execution of trigger 'SCOTT.TEST'
    ORA-06512: at "SCOTT.TEST", line 2
    ORA-04088: error during execution of trigger 'SCOTT.TEST'
    I dont seem to find a way to figure out this thing, b'cos the only way I fire the trigger is when I want to insert a new row and trigger should be working on that new row.
    confused any expert's expertise is appreciated
    Thanks
    Srikanth

    I know Justin is still around, but this thread is... 8 years old... so please, create your own thread, describing your environment such as database version in first place, and your problem.
    Thanks for your cooperation.
    Nicolas.
    +-- for the safety, thread locked --+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for