Sequence, nextval

Hello,
i'm writing an application, that has to have process unique index. I think of db-sequences for to create them. So i use jdbc and sql to retrieve the next value from the sequence.
i do that by sequenceName.nextVal
I wonder how to form the valid sql statement to retrieve the netx index of the sequence. Things like 'SELECT SQ_JOBNOS.nextval' caause oracle exceptions.
do i have to create a temporary table?
thanks a lot,
best regards,
nigoooh

SELECT SQ_JOBNOS.nextval FROM dual

Similar Messages

  • Insert Select sequence.nextval Problme

    Hi,
    I am trying to insert records in the table using query similar to
    insert into table1 (id, col1, col2)
    select
    sequence.nextval
    t1. col1, t1.col2
    from table t1;
    I am getting following error
    ORA-02287: sequence number not allowed here
    Will you please let me know how to resolve this?
    Regards
    ~Pravin

    Hmm...
    See here ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>
    satyaki>
    satyaki>create table ff_gg
      2      (
      3        a_col   number(5),
      4        b_col   varchar2(30)
      5      );
    Table created.
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>
    satyaki>create sequence dd_qq
      2     start with 1
      3     increment by 1;
    Sequence created.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>insert into ff_gg
      2     select rn, ename
      3     from (
      4            select dd_qq.nextval, ename
      5            from emp
      6          );
              select dd_qq.nextval, ename
    ERROR at line 4:
    ORA-02287: sequence number not allowed here
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>ed
    Wrote file afiedt.buf
      1  insert into ff_gg
      2     select dd_qq.nextval rn, ename
      3     from (
      4            select ename
      5            from emp
      6*         )
    satyaki>/
    12 rows created.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>select * from ff_gg;
         A_COL B_COL
             1 WARD
             2 MARTIN
             3 SCOTT
             4 KING
             5 TURNER
             6 ADAMS
             7 JAMES
             8 FORD
             9 MILLER
            10 Smith
            11 Glen
         A_COL B_COL
            12 boock
    12 rows selected.
    Elapsed: 00:00:00.00
    satyaki>Got me?
    Regards.
    Satyaki De.

  • Top 5 queries  - One of them is sequence.nextval from dual !!!!!

    Hi All,
    I am using ORACLE DATABASE 11g and Oracle Linux 5.
    My intentions are to get the top resource consuming or time consuming queries from database in the particular time frame. I formed the below query to get the same :-
    select a.SQL_FULLTEXT,
                 s.module,
                 s.cpu_time_total / 1000000,
                 s.iowait_total / 1000000,
                 s.fetches_total,
                 s.sorts_total,
                 s.executions_total,
                 s.loads_total,
                 s.disk_reads_total /
                 DECODE(s.executions_total, 0, 1, s.executions_total) reads_per_execution,
                 s.disk_reads_total,
                 s.direct_writes_total / 1024,
                 s.buffer_gets_total / 1204,
                 s.rows_processed_total,
                 s.elapsed_time_total / 1000000,
                 s.apwait_total / 1000000,
                 s.ccwait_total / 1000000,
                 s.plsexec_time_total / 1000000,
                 s.javexec_time_total / 1000000
            from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT h, v$sqlarea a
           where s.parsing_schema_name = 'ST'
             and s.executions_total != 0
             and s.snap_id = h.snap_id
             and a.SQL_ID = s.sql_id
             and h.begin_interval_time > '03-NOV-11 09.30.00.000 AM'
             and h.end_interval_time < ''03-NOV-11 12.30.59.999 PM'
             and rownum <= 5
           order by 15 desc;I assume that above query will give me top 5 sql or pl/sql queries which are consuming most resource or time. Please correct me if am wrong with the query.
    The surprising fact is that I got the below query as the top most resource consuming query :-
    SELECT REF_SEQ.NEXTVAL AS VAL FROM DUALI searched for all the code in the database and I was not able to find this line in any code. The fact is that this query should not take more than 1 second as we know that sequence nextval from dual table is very fast so, how can i get this as resource consuming query.
    The output is as follows :- ( I have modified the output to show all the facts in detail. Here you can see that it shows the execution time as 10.002467 Seconds. In real this will get execute in less than a second.)
    MODULE NAME := Banking
    TOTAL CPU TIME := 8.299744 Seconds.
    TOTAL IO WAIT TIME := .915287 Seconds.
    TOTAL RECORDS FETCHED := 41128 Rows.
    SORT OPERATION(S) := 0
    TOTAL NO. OF EXECUTION(s) := 41128 Times.
    TOTAL NO. OF TIME(S) OBJECT/QUERY LOADED/RELOADED := 5
    DATA READ PER EXECUTION := .002139661544446605718731764248200739155806 KB.
    TOTAL DISK READS := 88 KB.
    TOTAL DISK WRITES := 0 KB.
    TOTAL BUFFER READS := 4.92441860465116279069767441860465116279 KB.
    TOTAL NO. OF ROW(S) PROCESSED := 41128
    TOTAL EXECUTION TIME FOR ONE TRANSACTION := 10.002467 Seconds.
    APPLICATION WAIT TIME := 0 Seconds.
    CONCURRENCY WAIT TIME := .344575 Seconds.
    PL/SQL EXECUTION TIME := 0 Seconds.
    JAVA EXECUTION TIME := 0 Seconds.Please guide me for this method. How to understand the presence of this sequence.nextval query here.
    The base requirement is I want a query which will give me top 5 resource/time consuming queries. I have took the help of AWR views in my logic. If you have any better idea let me know.
    Thanks in advance.

    Try this
    select *
    from
    select a.SQL_FULLTEXT,
                 s.module,
                 s.cpu_time_total / 1000000,
                 s.iowait_total / 1000000,
                 s.fetches_total,
                 s.sorts_total,
                 s.executions_total,
                 s.loads_total,
                 s.disk_reads_total /
                 DECODE(s.executions_total, 0, 1, s.executions_total) reads_per_execution,
                 s.disk_reads_total,
                 s.direct_writes_total / 1024,
                 s.buffer_gets_total / 1204,
                 s.rows_processed_total,
                 s.elapsed_time_total / 1000000,
                 s.apwait_total / 1000000,
                 s.ccwait_total / 1000000,
                 s.plsexec_time_total / 1000000,
                 s.javexec_time_total / 1000000
            from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT h, v$sqlarea a
           where s.parsing_schema_name = 'ST'
             and s.executions_total != 0
             and s.snap_id = h.snap_id
             and a.SQL_ID = s.sql_id
             and h.begin_interval_time > '03-NOV-11 09.30.00.000 AM'
             and h.end_interval_time < '03-NOV-11 12.30.59.999 PM'
             order by 15 desc
    )where rownum <= 5

  • Sequence nextval reset at every month with 1

    I want to change Sequence Nextval = 1 at every month
    I m using this sequence
    create sequence VoucherNo
    minvalue 1
    maxvalue 9999999
    start with 1
    increment by 1
    Order;i want then when start next month sequence nextval should be 1 .
    reset with 1.

    Dont't recreate the sequence! You would invalidate all independent objects and lose all privileges granted for the sequences.
    Instead try this:SQL>CREATE SEQUENCE SEQ_TEST
      2   START WITH  1
      3   INCREMENT BY  1
      4   MINVALUE  1
      5   MAXVALUE  9999999;
    Sequence created.
    SQL>
    SQL>SELECT SEQ_TEST.NEXTVAL
      2    FROM all_objects WHERE ROWNUM < =10;
       NEXTVAL
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.
    SQL>
    SQL>DECLARE
      2     Val   NUMBER;
      3  BEGIN
      4     SELECT SEQ_TEST.CURRVAL
      5       INTO Val
      6       FROM DUAL;
      7
      8     EXECUTE IMMEDIATE 'ALTER SEQUENCE SEQ_TEST INCREMENT BY ' || TO_CHAR(1 - Val);
      9
    10     SELECT SEQ_TEST.NEXTVAL
    11       INTO Val
    12       FROM DUAL;
    13
    14     EXECUTE IMMEDIATE 'ALTER SEQUENCE SEQ_TEST INCREMENT BY 1';
    15
    16     DBMS_OUTPUT.put_line('New value of SEQ_TEST is ' || TO_CHAR(Val));
    17  END;
    18  /
    New value of SEQ_TEST is 1hth, Urs

  • Sequence nextval jumps by 20

    Always wondered about this. Why does a sequence nextval sometimes jump by 20 from the previous val when the increment is 1? Ever see this before?

    Technically, I cannot think of one. The locking implications would be really unfortunate. Often, this is put in as a "requirement" to fulfill some perceived legal or accounting issue (i.e. all Purchase Order numbers accounted for) but it's usually possible & appropriate for the technical folks to push back-- 99% of the time there are other technical options that are far friendlier and more scalable that solve the underlying issue.
    Justin

  • Goldengate replicat slow to process sequence.nextval

    GGS replicat takes 45 minutes to process this statement. Tracing the replicat session shows that replicat is continuously altering the sequence on the target. The statement completes on the source in less than 1 minute. Any ideas on how I can speed this up.
    Thanks,
    Lynn
    insert into test_tab2
    select MYSEQ_ID.nextval,OR_DATETIME_ID,LOCATION_ID, CLINIC_ID ,ACCESSION_COUNTS
    from
    (select * from summary.CLINIC_MV
    where order_datetime_id >
    (select mor_datetime_id) - 40 from summary.CLINIC_MV))

    Identified OS issue. Not a GGS issue.

  • USE sequence.nextval in SQL statement

    Hi,
    I want to use SEQUENCE_name.NEXVAL in our query.
    But it gives error
    ora-02287: sequence number not allowed here
    Select distinct dd.agreementid,dd.cityid,dd.bankid,dd.bankbranchid,zz.bankbranchdesc,
    account_no,account_type,Sysdate,'A',Null,'1001',Sysdate,NULL,NULL,
    ELEC_PMNT_SEQ.Nextval seq_num
    From pdi.pdi_instr_d_tmp dd,
    pdi.pdi_bankbranch_m zz,
    pdi.pdi_bankaccount_tmp t
    Where t.agreementid = dd.agreementid
    And dd.cityid = zz.cityid
    And dd.bankid = zz.bankid
    And dd.bankbranchid= zz.bankbranchid
    And dd.mc_status = 'M' And dd.status = 'M' And instr_type <> 'P'
    Thanks & Regards
    K S Ratan

    You can use a subquery, but maybe have you need an order by clause ?
    SQL> ed
    Wrote file afiedt.buf
      1* select distinct username, MySeq.nextval from dba_users
    SQL> /
    select distinct username, MySeq.nextval from dba_users
    ERROR at line 1:
    ORA-02287: sequence number not allowed here
    SQL> ed
    Wrote file afiedt.buf
      1  select a.*, MySeq.nextval
      2* from (select distinct username from dba_users order by username) a
    SQL> /
    USERNAME                          NEXTVAL
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> /
    USERNAME                          NEXTVAL
    DBSNMP                                  8
    H89UCBAC                                9
    OUTLN                                  10
    PEOPLE                                 11
    PS                                     12
    SYS                                    13
    SYSTEM                                 14
    7 rows selected.Is this do you want ? Sequence will increment on each query execution, or did you want the number of output line to have the same result on each sql execution :
    SQL> ed
    Wrote file afiedt.buf
      1  select a.*, rownum
      2* from (select distinct username from dba_users order by username) a
    SQL> /
    USERNAME                           ROWNUM
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> /
    USERNAME                           ROWNUM
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> Nicolas.
    Sorry Laurent, you've already showed that works with subquery...
    Message was edited by:
    N. Gasparotto

  • Passing sequence nextval in insert statement

    Hi,
    Want to insert a record in table A using incremented sequence value to be get inserted in the ID column of table.
    ID column is having a primary key constraint
    created sequence test1_seq for that table
    How to use this sequence number's NEXTVAL to be get inserted in ID column of table A, along with other data.
    How to pass the values to the below procedure for inserting record ?
    There are total six fields in the column
    execute pk_test1.insert_test1('*How to pass next sequence value here ?*','rec2','rec3','rec4','rec5','rec6')
    With Regards
    Edited by: user640001 on Aug 10, 2010 12:25 AM

    Check this: You can create a trigger to insert a sequence value in to a table for every insert that happens:
    SQL> create table my_Test1(col1 number,col2 VARCHAR2(100));
    Table created.
    SQL> ed
    Wrote file afiedt.buf
      1  create sequence test1_seq
      2  start with 1
      3  increment by 1
      4  maxvalue 999999999
      5  nocycle
      6  nocache
      7* noorder
    SQL> /
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace package pkg1_test as
      2  procedure insert_tab1(p_val1 VARCHAR2);
      3* end;
    SQL> /
    Package created.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace package body pkg1_test as
      2  procedure insert_tab1(p_val1 varchar2) is
      3  begin
      4  insert into my_test1(col2) values(p_val1);
      5  COMMIT;
      6  END;
      7* end;
    SQL> /
    Package body created.
    SQL> create trigger my_trig1 before insert on my_test1
      2  for each row
      3  declare
      4  v_seqno NUMBER := 0;
      5  BEGIN
      6  SELECT test1_seq.nextval into v_seqno from dual;
      7  :new.col1 := v_seqno;
      8  end;
      9  /
    Trigger created.
    SQL> exec pkg1_test.insert_tab1(100);
    PL/SQL procedure successfully completed.
    SQL> select * from my_Test1;
          COL1 COL2
             1 ABCD
             2 100
    SQL> select test1_seq.currval from dual;
       CURRVAL
             2
    SQL> Edited by: AP on Aug 10, 2010 12:38 AM

  • To access a sequence.nextval from Infobus applet

    Hi
    I have Infobus Dataform applet which displays the columns of the
    table - timesheets which has a column "line_item" which has to
    get it's value from a database sequence.
    So I followed the approach followed in the Acme - sample
    application ViewMembers.java.
    Which the row added event of the RowsetInfo -
    The following code was added with my Rowset and sequence used.
    void ACME_MEMBERSIter_rowAdded(RowChangeEvent e) throws
    java.sql.SQLException,
    javax.infobus.DuplicateColumnException,
    javax.infobus.ColumnNotFoundException,
    javax.infobus.InvalidDataException
    RowsetAccess rsa = e.getDataItem();
    DbAccess dba = rsa.getDb();
    RowsetAccess seq = null;
    seq = (RowsetAccess)dba.executeRetrieval(
    "select acme_member_id_seq.nextval as
    \"new_id\" from dual",
    "infobus:/oracle/sessionInfo1/new_id",
    null);
    ImmediateAccess nv = null;
    ImmediateAccess column_id = null;
    nv = (ImmediateAccess)seq.getColumnItem("new_id");
    column_id = (ImmediateAccess)rsa.getColumnItem
    ("MEMBER_ID");
    column_id.setValue(nv.getValueAsString());
    This does not work when I run it from Jdeveloper I have debugged
    it an umpteen times and still no clue.
    The statement
    (RowsetAccess)dba.executeRetrieval(
    "select acme_member_id_seq.nextval as
    \"new_id\" from dual",
    "infobus:/oracle/sessionInfo1/new_id",
    null);
    JUST DOES NOT WORK.
    Please help.
    Regards
    Rajs
    null

    Hi Shachar,
    When SEQUENCE_SETUP/RESETUP is called, I need to modify the arbitrary data.
    Arbitrary data can be accessed in 2 ways (as per my knowledge)
    1. GetNewStreamValue() & SetStreamValue() (for this I need AEGP_EffectRef which will be NULL for the new effect when it comes to SEQUENCE_SETUP/RESETUP).
    2. If PF_ParamDef* params is not NULL then,
         PF_Handle                arbH        = params[PARAM_ID]->u.arb_d.value;
        CG_ArbData                *arbP;
        arbP    = reinterpret_cast<CG_ArbData*>(PF_LOCK_HANDLE(arbH));
    In the first way, when SEQUENCE_SETUP/RESETUP is called AEGP_EffectRef is NULL, so I cannot use it.
    In the second way, when SEQUENCE_SETUP/RESETUP is called  PF_ParamDef* params is NULL, so I cannot use it.
    Any ideas?

  • Oracle native sequencing: nextVal executed two times.

    We are migrating from Weblogic 6.1 sp 5 & TopLink 3.6.3 to Weblogic 8.1 sp 2 & TopLink 9.0.4 and we are having this issue:
    It seems that when assigning the sequence to new objets TopLink execs the nextVal for the sequence twice. In fact we probably wouldn't notticed it if it was just that, the problem is that TopLink seems to register the object into the cache with an oid and assigning the next one to the object stored in the database so we are getting NoSuchObjectException each time we try to access them.
    Here is a dump of TopLink's log showing the problem:
    [TopLink]: ServerSession(22807116)--Connection(0)--client acquired
    [TopLink]: ClientSession(25858791)--Connection(0)--acquire unit of work: 10772417
    [TopLink]: UnitOfWork(10772417)--Connection(0)--JTS register
    [TopLink]: ServerSession(22807116)--Connection(17740413)--SELECT SEQ_BOOK.NEXTVAL FROM DUAL
    [TopLink]: ServerSession(22807116)--Connection(17558511)--SELECT SEQ_PAGE.NEXTVAL FROM DUAL
    [TopLink]: UnitOfWork(10772417)--Connection(0)--Before JTS Completion
    [TopLink]: UnitOfWork(10772417)--Connection(25919386)--Begin batch statements
    [TopLink]: UnitOfWork(10772417)--Connection(25919386)--INSERT INTO AUTHOR (NAME, OCA, OID) VALUES (?, ?, ?)
    [TopLink]: UnitOfWork(10772417)--Connection(0)-- bind => [Roger Penrose, 2004-05-11 18:54:01.917, 442803]
    [TopLink]: UnitOfWork(10772417)--Connection(25919386)--End Batch Statements
    [TopLink]: ClientSession(25858791)--Connection(25919386)--Begin batch statements
    [TopLink]: ClientSession(25858791)--Connection(25919386)--INSERT INTO BOOK (NAME, OCA, OID, OID_AUTHOR) VALUES (?, ?, ?, ?)
    [TopLink]: ClientSession(25858791)--Connection(0)-- bind => [The Emperor's New Mind, 2004-05-11 18:54:01.92, 347404, 442803]
    [TopLink]: ClientSession(25858791)--Connection(0)-- bind => [Shadows of the Mind, 2004-05-11 18:54:01.943, 347405, 442803]
    [TopLink]: ClientSession(25858791)--Connection(25919386)--End Batch Statements
    [TopLink]: UnitOfWork(10772417)--Connection(0)--After JTS Completion
    [TopLink]: UnitOfWork(10772417)--Connection(0)--release unit of work
    [TopLink]: ClientSession(25858791)--Connection(0)--client released
    [TopLink]: ServerSession(22807116)--Connection(0)--client acquired
    [TopLink]: ClientSession(116689)--Connection(0)--acquire unit of work: 32580168
    [TopLink]: UnitOfWork(32580168)--Connection(0)--JTS register
    [TopLink]: UnitOfWork(32580168)--Connection(0)--Before JTS Completion
    [TopLink]: UnitOfWork(32580168)--Connection(17129104)--Begin batch statements
    [TopLink]: UnitOfWork(32580168)--Connection(17129104)--INSERT INTO AUTHOR (NAME, OCA, OID) VALUES (?, ?, ?)
    [TopLink]: UnitOfWork(32580168)--Connection(0)-- bind => [Benoit Mandelbrot, 2004-05-11 18:54:49.264, 442805]
    [TopLink]: UnitOfWork(32580168)--Connection(17129104)--End Batch Statements
    [TopLink]: ClientSession(116689)--Connection(17129104)--Begin batch statements
    [TopLink]: ClientSession(116689)--Connection(17129104)--INSERT INTO BOOK (NAME, OCA, OID, OID_AUTHOR) VALUES (?, ?, ?, ?)
    [TopLink]: ClientSession(116689)--Connection(0)-- bind => [Les objets fractals, forme, hasard et dimension, 2004-05-11 18:54:49.266, 347409, 442805]
    [TopLink]: ClientSession(116689)--Connection(0)-- bind => [The Fractal Geometry of Nature, 2004-05-11 18:54:49.282, 347408, 442805]
    [TopLink]: ClientSession(116689)--Connection(17129104)--End Batch Statements
    [TopLink]: UnitOfWork(32580168)--Connection(0)--After JTS Completion
    [TopLink]: UnitOfWork(32580168)--Connection(0)--release unit of work
    [TopLink]: ClientSession(116689)--Connection(0)--client released
    the test is about creating two objects (well, we are actually creating 6 objects in this sample as we are creating two "master" objects and adding two related (in a one to many relationship) objects to each one.)
    The thing I would like you to notice is this:
    The first AUTHOR object gets assigned the OID 442803 wether the next AUTHOR object gets the OID 442805 although we expected it to be 442804.
    The same occurs with the objects in the "many" side of the relation. They get sibiling OIDs but with a gap of two OIDs when creating the last two.
    I have been searching for simmilar problems in this forums and I found two posts:
    Both where related to a bug of an older version of TopLink (9.0.3 I think) when using something different than a number for the sequence field of an object. I expect it to be fixed in 9.0.4 version as it seemed to be fixed even for the 9.0.3 version. May it be a regression bug?
    Anyway, we are using BigDecimal on entity bean's sequence number and IIRC NUMBER(18) in Oracle tables.
    Currently our TopLink version is: 9.0.4 (031126)
    Our native sequence has an allocation size of 200 and it matches with SEQUENCEs defined in Oracle.
    As we are migratting from TopLink 3.6.3 and we have not changed the sequence prealocation size (we have not touched the database at all) we don't expect the problem to be on sequence prealocation.
    I must say we have changed the "default" JDBC driver that TopLink uses when doing the issuing the loging phase (which I think is a SUN driver) to an oracle.jdbc.driver.OracleDriver as we were having problems with timestamp locking.
    Any idea?
    Thanks in advance.
    Ignacio.

    Solved!
    It was my fault. I was doing a really nasty thing to the entity beans.
    I must publicly thank my work mate (which is a pretty smart girl, I must say) in tracking down this issue.
    Here is what (we think) was happening:
    As I told in previous post in this post we are in the process of moving from TopLink 3.6.3 (EJB 1.1) to TopLink 9.0.4 (EJB 2.0). We do have a "super class" in our application where we had some common things of our entity beans, i.e. entityContext, oid and oca attributes. We have also some methods that retrieve and set values from and to the entity beans via value objects (in order to avoid the heavy RMI operations when doing it through "standard" getters and setters) well, it happened that the current implementation of the "batch setting" method used the getDeclaringMethods to update in both UPDATE and INSERT opperations entity attributes with the data of the value object.
    When switching to EJB 2.0 we had to push down both the oid and oca attributes (in order of being able do deploy them) to each final entity bean and now they where being included in the setting process!
    You can imagine an scenario like this:
    1. ejbCreate() // TopLink issues the SELECT SEQ_XXX NEXT VAL FROM DUAL and sets the oid of the EJB
    2. setAttributes() // transfer info from the value object to the newly created EJB: including a setOid(null)!
    3. commit() (Before Completion)
    4. TopLink detects that the damm object surprisingly DOES NOT have the oid attribute setted so it performs another SELECT SEQ_XXX NEXT VAL FROM DUAL in order to "fix" this big problem.
    5. commit() (After Completion) // the object is written to the database with the second value from the sequence whereas the first value is used to identify the entity bean into the identity cache.
    Well it may not be "exactly" what is happening but I'm sure we are not so far from reality with our assumptions.
    Andrei Ilitchev, thanks for your interest, sorry I could not post this sooner.

  • Sequence.nextval doubles the returned value with Execute Statement (F9)

    There appears to be a quirk with sequences in Raptor.
    Has anyone noticed that depending on how you execute this sql (SELECT MYSEQ.NEXTVAL FROM DUAL;) the value returned is either the correct nextval or double what you expected?
    For example, MYSEQ is a simple sequence which increments by 1. If you Execute Statement (F9) then the value returned jumps by 2 instead of 1. If you Run Script (F5) then the value returns jumps by 1, as expected.
    If MYSEQ is changed to increment by 2. The when you Execute Statement (F9) then the value returned jumps by 4 instead of 2. If you Run Script (F5) then the value returns jumps by 2, as expected. No matter what you put for the increment by Execute Statement (F9) always doubles it.
    It always seems to be double. Executing the same scenario in TOAD always returns the correct value (i.e. properly increments).
    Is the query being executed multiple times with Execute Statement? Why is this happening?

    While there is no guarantee from Oracle that sequences produce sequential numbers, this is obviously a case where SQL Developer is running the select statement twice.
    The issue is that queries can actually change information, rather than just retrieve data from the database.
    The following package is a test case:
    create or replace package test_query is
    function get_next_count return number;
    end;
    create or replace package body test_query is
    cnt number := 0;
    function get_next_count return number is
    begin
    cnt := cnt + 1;
    return cnt;
    end;
    end;
    select test_query.get_next_count from dual;
    This query, which should return 1, 2, 3, 4, etc actually returns 2, 4, 6, 8, etc, because SQL Developer is running the select twice.

  • Synonym for sequence.nextval

    Hi all,
    I have an error on this
    Error(48,48): PL/SQL: ORA-02287: sequence number not allowed here
    SELECT MAX (capacity_id_seq) - capacity_id_seq.NEXTVAL
    INTO lv_new_importmaxrecord
    FROM capacity_current;
    Shoud I create a public synonym for this??to solve this...

    SQL>
    SQL> drop table t;
    Table dropped.
    SQL> drop sequence t_seq;
    Sequence dropped.
    SQL> create table t (x) as
    select rownum from all_objects
    where rownum <= 1000;
    Table created.
    SQL>
    SQL> create sequence t_seq;
    Sequence created.
    SQL>
    declare
      n number;
    begin
      select max(x) - t_seq.nextval
      into n
      from t;
      dbms_output.put_line(n);
    end;
      select max(x) - t_seq.nextval
    ERROR at line 4:
    ORA-06550: line 4, column 25:
    PL/SQL: ORA-02287: sequence number not allowed here
    ORA-06550: line 4, column 3:
    PL/SQL: SQL Statement ignored
    SQL>
    SQL> set serveroutput on size 1000000
    SQL>
    declare
      n number;
    begin
      select maxn - t_seq.nextval
      into n
      from (select max(x) as maxn from t);
      dbms_output.put_line(n);
    end;
    999
    PL/SQL procedure successfully completed.
    SQL>
    SQL>pratz

  • Sequence.nextval and insertXML()

    Hi there!
    Can anyone advise on how to use both nextval and insertXML() together?
    Is there a batch nextval option?
    Thanks!

    Dont't recreate the sequence! You would invalidate all independent objects and lose all privileges granted for the sequences.
    Instead try this:SQL>CREATE SEQUENCE SEQ_TEST
      2   START WITH  1
      3   INCREMENT BY  1
      4   MINVALUE  1
      5   MAXVALUE  9999999;
    Sequence created.
    SQL>
    SQL>SELECT SEQ_TEST.NEXTVAL
      2    FROM all_objects WHERE ROWNUM < =10;
       NEXTVAL
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.
    SQL>
    SQL>DECLARE
      2     Val   NUMBER;
      3  BEGIN
      4     SELECT SEQ_TEST.CURRVAL
      5       INTO Val
      6       FROM DUAL;
      7
      8     EXECUTE IMMEDIATE 'ALTER SEQUENCE SEQ_TEST INCREMENT BY ' || TO_CHAR(1 - Val);
      9
    10     SELECT SEQ_TEST.NEXTVAL
    11       INTO Val
    12       FROM DUAL;
    13
    14     EXECUTE IMMEDIATE 'ALTER SEQUENCE SEQ_TEST INCREMENT BY 1';
    15
    16     DBMS_OUTPUT.put_line('New value of SEQ_TEST is ' || TO_CHAR(Val));
    17  END;
    18  /
    New value of SEQ_TEST is 1hth, Urs

  • Please Help me with long time oracle  select sequence.nextval from dual

    Hi
    I'm in a real problem.In fact i have a J2EE5(JPA,Hibernate 3,EJB 3.0) project deployed at websphere 6 application server and i'm using Oracle 10 g R2.
    Well i have a batch job that inserts into some table called AVERAGEBALANCE.
    the problem is that when i have activated hibernate log i discoverd that the select from dual is the longest sql (it takes some times over second !!)
    here is the log
    11/07/2011 08:49:40,406 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - insert into AVERAGEBALANCE (CDATE_, CUSER_, AVERAGEBALANCE_, AVERAGECREDITORBALANCE_, AVERAGEDEBITORBALANCE_, BEGINDATE_, CALCULATIONDATE_, CASHSUBACCOUNTCODE_, CASHSUBACCOUNTPK_, CODE_, ENDDATE_, NBCREDITORDAYS_, NBDEBITORDAYS_, TEDABCALCULATIONPERIODICITYPK_, VERSIONNUM_, PK_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    11/07/2011 08:49:40,468 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - select this_.PK_ as PK1_465_0_, this_.CDATE_ as CDATE2_465_0_, this_.CUSER_ as CUSER3_465_0_, this_.UUSER_ as UUSER4_465_0_, this_.BALANCE_ as BALANCE5_465_0_, this_.BALANCETYPE_ as BALANCET6_465_0_, this_.CASHSUBACCOUNTPK_ as CASHSUBA8_465_0_, this_.CASHSUBACCOUNTCODE_ as CASHSUBA7_465_0_, this_.CODE_ as CODE9_465_0_, this_.CURRENCYPK_ as CURRENCYPK11_465_0_, this_.CURRENCYCODE_ as CURRENC10_465_0_, this_.ENDDATE_ as ENDDATE12_465_0_, this_.EXCHANGERATE_ as EXCHANG13_465_0_, this_.ORIGINBALANCEPK_ as ORIGINB15_465_0_, this_.ORIGINBALANCECODE_ as ORIGINB14_465_0_, this_.POSITIONDATE_ as POSITIO16_465_0_, this_.REVALUATIONDATE_ as REVALUA17_465_0_, this_.SUMOFCREDITS_ as SUMOFCR18_465_0_, this_.SUMOFDEBITS_ as SUMOFDE19_465_0_, this_.UDATE_ as UDATE20_465_0_, this_.VERSIONNUM_ as VERSIONNUM21_465_0_ from CASHAB this_ where this_.CASHSUBACCOUNTCODE_=? and this_.BALANCETYPE_=? and this_.POSITIONDATE_<? and this_.ENDDATE_>=? and this_.BALANCE_<>?
    11/07/2011 08:49:40,468 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - select AVERAGEBALANCE_.nextval from dual
    11/07/2011 08:49:41,484 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - insert into AVERAGEBALANCE (CDATE_, CUSER_, AVERAGEBALANCE_, AVERAGECREDITORBALANCE_, AVERAGEDEBITORBALANCE_, BEGINDATE_, CALCULATIONDATE_, CASHSUBACCOUNTCODE_, CASHSUBACCOUNTPK_, CODE_, ENDDATE_, NBCREDITORDAYS_, NBDEBITORDAYS_, TEDABCALCULATIONPERIODICITYPK_, VERSIONNUM_, PK_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)well i have increased the sequence cache in fact here is the creation code of the sequence.
    CREATE SEQUENCE  "COMPTAPERF5"."AVERAGEBALANCE_"  MINVALUE 1 MAXVALUE 999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 400 NOORDER  NOCYCLE   ;i think that there is some oracle parameter to tune
    Thanks in advance
    Edited by: B.Mansour Nizar on 11 juil. 2011 01:04
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:33
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:34
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:34
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:35
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:35
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:36
    Edited by: B.Mansour Nizar on 15 juil. 2011 07:42

    I found it.
    It's not due to oracle but it's a hibernate issue.In fact if setting FlushMode to Manual.It wil flush the in memory entities after that it will fire the insert statement.
    Here's the log.
    15/07/2011 15:32:47,984 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - select CASHAB_.nextval from dual
    15/07/2011 15:32:47,984 TRACE AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - preparing statement
    15/07/2011 15:32:47,984 DEBUG SequenceGenerator:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Sequence identifier generated: 20441
    15/07/2011 15:32:47,984 DEBUG AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    15/07/2011 15:32:47,984 TRACE AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - closing statement
    15/07/2011 15:32:47,984 DEBUG ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - aggressively releasing JDBC connection
    15/07/2011 15:32:47,984 DEBUG ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    15/07/2011 15:32:47,984 DEBUG AbstractSaveEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - generated identifier: 20441, using strategy: org.hibernate.id.SequenceHiLoGenerator
    15/07/2011 15:32:47,984 TRACE AbstractSaveEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - saving [com.bfi.cpt.bal.cas.CashAccountingBalance#20441]
    15/07/2011 15:32:47,984 TRACE Versioning:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - using initial version: 0
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - flushing session
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing flush-time cascades
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.cht.cas.CashSubAccount
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - done processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.cht.cas.CashSubAccount
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.ref.cur.Currency
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - done processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.ref.cur.Currency
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.bal.cas.CashAccountingBalance
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - done processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.bal.cas.CashAccountingBalance
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - dirty checking collections
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Flushing entities and processing referenced collections
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Processing unreferenced collections
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Scheduling collection removes/(re)creates/updates
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Flushed: 1 insertions, 0 updates, 0 deletions to 3 objects
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - listing entities:
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - com.bfi.ref.cur.Currency{translatedName=null, certain=false, iso3166=788, quotity=1, identifier=TND, creationUser=admin, internalCode=null, name=Dinars Tunisien, creationDate=2011-07-11 14:43:06, code=TND, versionNum=0, decimal=3, updateUser=null, updateDate=null, pk=136, decimalName=millimes}
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - com.bfi.cpt.bal.cas.CashAccountingBalance{cashSubAccount=com.bfi.cpt.cht.cas.CashSubAccount#400201, originBalanceCode=null, exchangeRate=null, sumOfDebits=0.0, endDate=31 décembre 9999, creationUser=bna, currencyPk=136, creationDate=2011-07-15 15:32:47, cashSubAccountCode=BNA/PCI_BNA/82-TND, code=2010-07-30/BNA/PCI_BNA/82-TND/AccountingDateBalance/TND, versionNum=0, originBalancePk=null, currency=com.bfi.ref.cur.Currency#136, updateUser=null, originBalance=null, balanceType=AccountingDateBalance, updateDate=null, positionDate=30 juillet 2010, sumOfCredits=10.0, pk=20441, cashSubAccountPk=400201, revaluationDate=null, balance=-10.0, currencyCode=TND}
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - com.bfi.cpt.cht.cas.CashSubAccount{name2=null, accountPk=81, name=null, versionNum=0, currency=com.bfi.ref.cur.Currency#136, updateDate=null, chartByEntity=com.bfi.cpt.cht.std.ChartByEntity#2, refAccount=null, currencyCode=TND, chartByEntityCode=BNA/PCI_BNA, refAccountCode=null, creationDate=2011-07-15 15:25:45, account=com.bfi.cpt.cht.cas.StandardAccount#81, freeKey10=null, freeKey11=null, chartByEntityPk=2, freeKey12=null, updateUser=null, refAccountPk=null, freeKey13=null, freeKey14=null, freeKey15=null, freeKey16=null, freeKey17=null, accountCode=PCI_BNA/81, freeKey18=null, freeKey19=null, freeKey0=null, freeKey1=null, freeKey2=null, freeKey3=null, freeKey4=null, freeKey5=null, freeKey6=null, freeKey7=null, freeKey8=null, freeKey9=null, number=82-TND, creationUser=bna, freeKey20=null, freeKey21=null, freeKey22=null, freeKey23=null, freeKey24=null, freeKey25=null, freeKey26=null, freeKey27=null, freeKey28=null, freeKey29=null, currencyPk=136, code=BNA/PCI_BNA/82-TND, freeKey30=null, freeKey31=null, freeKey32=null, pk=400201}
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - executing flush
    15/07/2011 15:32:47,984 TRACE ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - registering flush begin
    15/07/2011 15:32:47,984 DEBUG UpdateTimestampsCache:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Pre-invalidating space [CASHAB]
    15/07/2011 15:32:47,984 TRACE AbstractEntityPersister:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Inserting entity: [com.bfi.cpt.bal.cas.CashAccountingBalance#20441]
    15/07/2011 15:32:47,984 TRACE AbstractEntityPersister:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Version: 0
    15/07/2011 15:32:47,984 DEBUG AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    15/07/2011 15:32:47,984 DEBUG ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - opening JDBC connection
    15/07/2011 15:32:47,984 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - insert into CASHAB (CDATE_, CUSER_, BALANCE_, BALANCETYPE_, CASHSUBACCOUNTCODE_, CASHSUBACCOUNTPK_, CODE_, CURRENCYCODE_, CURRENCYPK_, ENDDATE_, POSITIONDATE_, SUMOFCREDITS_, SUMOFDEBITS_, VERSIONNUM_, PK_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)Edited by: B.Mansour Nizar on 15 juil. 2011 07:38
    Edited by: B.Mansour Nizar on 15 juil. 2011 07:39
    Edited by: B.Mansour Nizar on 15 juil. 2011 07:43

  • Sequence nextval after an schema level export import

    If I export a schema that has some sequences and then truncate tables and then import the schema, do I get theh old sequence values?
    I guess my question is do sequences get stored at the schema level or the database level.
    I noticed that sequences are exported at the schema level when I do an export so that may be the answer but your confirmation would be appreciated.

    Hi,
    Nothing to worry,imp/exp does not change the value of Nextval.you can use truncate table after exp, then u can import it.
    Regards
    Vinay Agarwal
    OCP

Maybe you are looking for