Cache sequence

Hi All,
I have a straight insert/select -
insert into t_tab
(p_id,
p_name,
p_ser_id,
p_flag)
select my_seq.nextval,
p_name,
p_ser_id,
p_flag
from my_table
The table my_table has about 500K records. It takes lot of time.
Most time spent that sequence returs the next_val too slow.
I am thinking to cache the seq before the select - like
alter sequence MY_SEQ cache 10000000
Do I need to alter it back again to no cache mode or default cache after the
insert in done. If yes then whats the syntax for that.
Also, any suggestion to use append / parallel here.
Thanks a lot.
ds

You can find the current setting of the cache size by querying the CACHE_SIZE column in the USER_SEQUENCES view.
Setting it to value 10000000, seems a bit over the top if you ask me.
I'd increase the current setting by a factor of 100, maybe 500, and see how the performance gains from that.
If yes then whats the syntax for that. Same syntax. Just use the current setting you found in USER_SEQUENCES.

Similar Messages

  • Cached sequence

    i create a cached sequence of 30
    and i made
    select ddd.nextval from dual;
    from two differnt sessions but the number generated by the sequence where gap free,i exit the firsr session then log on again and the sequence where generted without gaps,so i think i did not understand the meaning what is cached index.

    Sequences are cached on the server for ALL sessions to use.... there is not a cache per session. Try selecting a sequence value, shutdown the database, start it back up, select another sequence value, and see the gap.
    Tom Best

  • Caching sequences in timesten

    I am trying to implement TimesTen in my application but stuck up with sequences. Can anyone guide me how can I take benefit of TimesTen caching for sequences

    oracle sequence but in in-memory timesten implementation

  • Pin the sequence WIP_JOB_NUMBER_S in the DB Buffer Cache

    hai,
    how u pin the sequence in db_buffer_cache?????
    ( The job numbers skip to
    the next set of 100 when a user exits and then logs in)
    for resolving this issue
    Pin the sequence WIP_JOB_NUMBER_S in the DB Buffer Cache so it
    does not get flushed.
    regards
    dba

    how did you pin it? have you done the following
    dbms_shared_pool.keep('WIP_JOB_NUMBER_S','Q').
    When you shut down a database normally, either "SHUTDOWN
    NORMAL" or "SHUTDOWN IMMEDIATE", the database takes care of
    making sure all sequences are "in sequence".
    If the database experiences instance failure or a "SHUTDOWN
    ABORT" statement is issued, you lose any unused cached
    sequence values.
    fadi

  • Gaps in sequences set to cache

    Would like to know if sequences are set to cache is it possable to see gaps in the sequence when a process like rman or a long period of time accures.
    I am trying to pin down why we have gaps. I read a little about if the system comes down then the sequence in cache memory would be lost and Oracle would get the next set of numbers.
    10.2.0.4
    linux
    Thank you,
    Steve

    user12551219 wrote:
    Would like to know if sequences are set to cache is it possable to see gaps in the sequence when a process like rman or a long period of time accures.
    I am trying to pin down why we have gaps. IOracle sequences will always have gaps for various reasons, a rollback is one, caching and database shutdowns are others. Caching sequences produces better performance.
    The answer is to not care that sequences have gaps.
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:4343369880986
    A sequence is a unique identifier and not a counter, storing a row count in a table is non-relational and does not perform or scale. If rows need to be counted they should be counted when they are selected.
    If you are concerned about losing numbers because you may run out, I wouldn't worry about that for a while either.
    Re: What kind of transaction in procedure?

  • Sequence and Cache

    I created a sequence:
    SQL> create sequence s
    increment by 1
    start with 1;
    then,
    SQL> select s.nextval from dual;
    1
    SQL> select s.nextval from dual;
    2
    it works fine.
    But when I shutdown my Windows2000 Server (where Oracle 9i is installed) and restart it again...
    SQL> select s.nextval from dual;
    32
    The default cache for sequence is 20.
    After reboot, the cahched sequence number are lost!
    Is there any way to keep the cached sequence number after reboot?
    What if I do the following: "SQL> alter sequence s cache 0; " ???
    What if the side-effect if I set the cache to 0 ??? Do you suggest to set it to zero ?
    thank you very much.
    Chu Ka Keong

    Just to elaborate a bit on Don's post.
    If you want to minimize the number of holes in a sequence, you must use the NOCACHE option when creating the sequence (or alter it that way). Be aware that this will NOT eliminate holes in the sequence. Any transaction that gets a value from the the sequence, and then rolls back, or otherwise does not write to the table, will "waste" a sequence number.
    Having said that, who really cares. The only, and I emphasise only, use for a sequence is to generate a guaranteed unique number for some purpose, either an ID, or a sequential number to make an otherwise duplicated key unique. Personally, I see absolutely no reason for a sequence in the second case.
    If you expect multiple users, and frequent "hits" to your sequence, use a big cache (I have some that cache 500) and damm the holes.

  • SEQUENCE CACHE

    제품 : ORACLE SERVER
    작성날짜 : 2003-08-04
    Sequence Cache
    오라클 sequence를 사용할 때에 cache라는 옵션을 가지고 있다.
    이러한 옵션을 사용할때 가끔 수자가 이어지지 않고 끊어지는 경우가 발생할 수
    있는데 여기서는 어떤 상황에서 수자가 없어지며 이러한 상황을 최소화할수 있는
    방법을 찾아보고자 한다.
    non-cache mode 인 경우에 'nextval' 을 요구하게 되면 current value에서 increment
    만큼의 값이 증가될 것이다. 예를 들어 current value는 0이고 increment는 1이며
    cache가 아닐 때 'nextval'을 요구하게 되면 1이 return 될 것이다.
    cache option과 같이 사용될 때 sequence에 대해서 'nextval'을 요구하게 되면
    cache 되는 만큼의 값에서부터 차례대로 next 값을 가져오게 되며 cache된 값을
    모두 사용하고 난 다음은 다음 caching 을 하게 된다.
    만약 다음과 같이 sequence가 선언되었다고 하자.
    create sequence seq increment by 1 cache 5;
    NUMBER SEQUENCE CACHE
    RETURNED CURRENT CURRENT
    start none 0 none
    1st access 1 5 1
    2nd access 2 5 2
    3rd access 3 5 3
    4th access 4 5 4
    5th access 5 5 5
    6th access 6 10 6
    7th access 7 10 7
    cache되어 있는 값들이 절대로 없어지지 않는다고 가정하면 출력되는 결과 값들은
    non-cache 의 그것과 다를 것이 없을 것이다.
    그러나 sequence cache도 역시 다른 cached information과 같이 shared pool 에 저장된다.
    이것은 다른 shared pool에 있는 procedure처럼 자주 access 되지 않으면 age out될 수
    있음을 의미하기도 한다. 또한 shutdown 시에는 cache에 있는 모든 것을 잃어버리게
    된다. 여기서 주로 shutdown에 의해 sequence의 번호가 skip 될수 있으므로 skip되어서는
    안되는 번호를 가진 응용프로그램에서는 non-cached sequence 를 사용해야 한다.
    다음에는 cache age out과 shutdown이후에 sequence number의 변화를 예를 들어 설명한다.
    NUMBER SEQUENCE CACHE
    RETURNED CURRENT CURRENT
    start none 0 none
    1st access 1 5 1
    2nd access 2 5 2
    cache aged out
    3rd access 5 10 5
    4th access 6 10 6
    shutdown
    5th access 10 15 10
    6th access 11 15 11
    7th access 12 15 12
    aging 문제를 해결하기 위해서 7.3 이후에서 부터는 dbms_shared_pool 이라는 package 를
    이용해서 shared pool내에 다음과 같이 고정시켜 놓을수 있다.
    dbms_shared_pool.keep('seq','Q');
    Reference Documents
    <Note:62002.1>

    제품 : ORACLE SERVER
    작성날짜 : 2003-08-04
    Sequence Cache
    오라클 sequence를 사용할 때에 cache라는 옵션을 가지고 있다.
    이러한 옵션을 사용할때 가끔 수자가 이어지지 않고 끊어지는 경우가 발생할 수
    있는데 여기서는 어떤 상황에서 수자가 없어지며 이러한 상황을 최소화할수 있는
    방법을 찾아보고자 한다.
    non-cache mode 인 경우에 'nextval' 을 요구하게 되면 current value에서 increment
    만큼의 값이 증가될 것이다. 예를 들어 current value는 0이고 increment는 1이며
    cache가 아닐 때 'nextval'을 요구하게 되면 1이 return 될 것이다.
    cache option과 같이 사용될 때 sequence에 대해서 'nextval'을 요구하게 되면
    cache 되는 만큼의 값에서부터 차례대로 next 값을 가져오게 되며 cache된 값을
    모두 사용하고 난 다음은 다음 caching 을 하게 된다.
    만약 다음과 같이 sequence가 선언되었다고 하자.
    create sequence seq increment by 1 cache 5;
    NUMBER SEQUENCE CACHE
    RETURNED CURRENT CURRENT
    start none 0 none
    1st access 1 5 1
    2nd access 2 5 2
    3rd access 3 5 3
    4th access 4 5 4
    5th access 5 5 5
    6th access 6 10 6
    7th access 7 10 7
    cache되어 있는 값들이 절대로 없어지지 않는다고 가정하면 출력되는 결과 값들은
    non-cache 의 그것과 다를 것이 없을 것이다.
    그러나 sequence cache도 역시 다른 cached information과 같이 shared pool 에 저장된다.
    이것은 다른 shared pool에 있는 procedure처럼 자주 access 되지 않으면 age out될 수
    있음을 의미하기도 한다. 또한 shutdown 시에는 cache에 있는 모든 것을 잃어버리게
    된다. 여기서 주로 shutdown에 의해 sequence의 번호가 skip 될수 있으므로 skip되어서는
    안되는 번호를 가진 응용프로그램에서는 non-cached sequence 를 사용해야 한다.
    다음에는 cache age out과 shutdown이후에 sequence number의 변화를 예를 들어 설명한다.
    NUMBER SEQUENCE CACHE
    RETURNED CURRENT CURRENT
    start none 0 none
    1st access 1 5 1
    2nd access 2 5 2
    cache aged out
    3rd access 5 10 5
    4th access 6 10 6
    shutdown
    5th access 10 15 10
    6th access 11 15 11
    7th access 12 15 12
    aging 문제를 해결하기 위해서 7.3 이후에서 부터는 dbms_shared_pool 이라는 package 를
    이용해서 shared pool내에 다음과 같이 고정시켜 놓을수 있다.
    dbms_shared_pool.keep('seq','Q');
    Reference Documents
    <Note:62002.1>

  • Sequence generation issue

    Hi , I am working in Healthcare industry . we have a claim and payment matching process . Every day 1.5 million payments get matched with 70 million claims and the matched payments are stores in some output table . After matching, an oracle seqence number is generated for each matched record and that is the primary key for the output table.
    Match query will be like this,.
    Select seqeunce1.nextval,a.column1,a.column2,b.coulmn1,b.column2 from claim_table a, payment_table b
    where a.column3=b.column3
    We are facing some seqence problem here. some sequence are missed during the first day and the missed sequnces are getting generated in the second day.
    Sequence Query:
    CREATE SEQUENCE ERA_CLAIM_MATCH_S
    START WITH 1
    MAXVALUE 999999999999999999999999999
    MINVALUE 1
    NOCYCLE
    CACHE 500
    NOORDER;
    Example to demonstrated the problem:
    Day 1(15th July) : sequence generated from 1 to 1000000 (some sequence are missed in between)
    Day2 (16th July) : sequence generated from 2500 to 2000000 (some missed sequence in day 1 are generated here)
    Our database in in RAC system.

    Hemant K Chitale wrote:
    I think that the question is : If the highest value generated on Day 1 was 1000000,  how could a value of 2500 be generated on Day 2 ?
    Shouldn't happen if the Sequence is a NOCYCLE.Hemant, but that is possible if Day 1's processing used the sequence on RAC instance 1 - whereas on Day 2, RAC instance 2 (with unused cached sequences from yesterday) is used.
    E.g.
    // on node 1
    SQL> create sequence testseq start with 1 increment by 1 nomaxvalue nocycle;
    Sequence created.
    SQL> select testseq.nextval, sys_context( 'user', 'instance_name' ) as instance from dual;
       NEXTVAL INSTANCE
             1 dev_1
    // on node 4
    SQL> select testseq.nextval, sys_context( 'user', 'instance_name' ) as instance from dual;
       NEXTVAL INSTANCE
            21 dev_4
    // on node 1, use the sequence a couple of times
    SQL> declare i integer; begin loop i := testseq.nextval(); exit when i > 100000; end loop; end;
      2  /
    PL/SQL procedure successfully completed.
    SQL> select testseq.nextval, sys_context( 'user', 'instance_name' ) as instance from dual;
       NEXTVAL INSTANCE
        100002 dev_1
    SQL>
    // on node 4, check the sequence
    SQL> select testseq.nextval, sys_context( 'user', 'instance_name' ) as instance from dual;
       NEXTVAL INSTANCE
            22 dev_4

  • Ordered Sequences in RAC

    We are currently in the process of migrating a single database to a RAC database under an aggressive time line. One of the issues we're currently facing is the use of sequences by our application. Various components of our app require ORDERED sequences (...terrible dependency, actually), and since these components can now connect to multiple instances with separate SGA's (with separately cached sequences), they produce bad results... fail!... "break"... Nothing new...
    Because of the aggressive time line, modifying each component in the application is not feasible.
    We've come up with a "temporary" solution:
    *1. Create a service called SEQSRV that is defined as having a preferred instance: INSTA and and available instance: INSTB with a TAF policy of BASIC.
    2. Create the necessary TNS entries for the service.
    3. Create a database link (SEQ).
    4. Create (recreate) the sequence(s) with appropriately tuned CACHE value NOORDERED (because they will be ORDERED by virtue of accessing only one instance).
    5. Create a synonym from the sequence(s) incorporating the database link
    sql> create synonym <synonym_name> for <sequence>@SEQ
    * - in case we have an issue with INSTA, requests will fail over to INSTB.
    I've tested this with a few options:
    a. CACHE=20, 5000, 1000000
    b. ORDERED, NORDERED
    c. from multiple concurrent clients.
    d. 'select sequence_synonym.nextval from dual' in a loop for iterations: 50, 5000, 2000000
    The test results showed solid performance for all runs, and the trace indicated a DSF locks were proportional to (CACHE/number of iterations). On higher iterations, there was a bit of recursive sql along with the usual TNS-related wait information, but nothing indicating poor performance.
    Can anyone comment on this? Is our logic flawed? Any suggestions? Anything?
    Jeffrey Frey
    Sr. Oracle DBA
    BondDesk Group Llc
    Edited by: jjfrey on Feb 11, 2009 12:17 PM

    Absolutely, the requirement "just" ordered... gaps are permitted between (for whatever reason), as long as the application's threads see chronologically incremented values.
    I'll be sure to test the TAF policies before implementing, when I test failover scenarios... thanks! great suggestion.
    So far, my most extreme test has been two simultaneous connections running 2,000,000 iterations of nextval ... results were comparable to a single without database links (with a few minor tweaks on CACHE value). Nothing in our application comes close to this kind of abuse; however, there are components that run 4 and 5 threads deep, but their requests for nextvals are typically more "serialized" and throttled by other factors (batch processing, AQ etc).
    As for busy database links, I have no issues increasing the number of sockets (distinct links) and grouping accordingly to avoid contention... will require some effort, but... effort is in the job description, right?
    Still think its feasible?
    Jeffrey

  • Create sequence

    in create sequence statement what z the use of cache/nocache?please tell me briefly.

    810045 wrote:
    in create sequence statement what z the use of cache/nocache?please tell me briefly.Fortunately this is described in the manuals that you refuse to read.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_6015.htm#i2067093
    >
    CACHE
    Specify how many values of the sequence the database preallocates and keeps in memory for faster access. This integer value can have 28 or fewer digits. The minimum value for this parameter is 2. For sequences that cycle, this value must be less than the number of values in the cycle. You cannot cache more values than will fit in a given cycle of sequence numbers. Therefore, the maximum value allowed for CACHE must be less than the value determined by the following formula:
    (CEIL (MAXVALUE - MINVALUE)) / ABS (INCREMENT)
    If a system failure occurs, then all cached sequence values that have not been used in committed DML statements are lost. The potential number of lost values is equal to the value of the CACHE parameter.
    Note:
    Oracle recommends using the CACHE setting to enhance performance if you are using sequences in an Oracle Real Application Clusters environment.
    NOCACHE
    Specify NOCACHE to indicate that values of the sequence are not preallocated. If you omit both CACHE and NOCACHE, then the database caches 20 sequence numbers by default.

  • Sequence generating duplicate numbers

    Hi guys,
    this might be more of a DBA question type... we had a situation where we copied data (once full schema and other time only tables ) from one database to another but ended up having sequence problem because new sequence was generating numbers which were lower than previousley generated one !
    I wonder if anyone had similar problem or know what could be causing it.
    when we copy full schema this happens to random table/sequences.
    Thanks for reading.
    Ali

    The sequence skipping behaviour is seen when cached sequences are exported.
    From the Oracle utilities manual
    >
    If transactions continue to access sequence numbers during an export, sequence numbers might be skipped. The best way to ensure that sequence numbers are not skipped is to ensure that the sequences are not accessed during the export.
    Sequence numbers can be skipped only when cached sequence numbers are in use. When a cache of sequence numbers has been allocated, they are available for use in the current database. The exported value is the next sequence number (after the cached values). Sequence numbers that are cached, but unused, are lost when the sequence is imported.
    >
    Hope this helps
    Varad

  • Keep Sequences in Shared Pool for RAC Environment

    Hi,
           We have 2 node RAC setup for production environment. I want to pin cached sequences in my database. We are using following command for this purpose.
    EXEC DBMS_SHARED_POOL.KEEP('HR.MySeq','Q');
    Do I need to execute this command for each single node?

    Pinning is in the Shared Pool in the SGA.  So it is local to an instance.
    Therefore, you would need to execute it in each instance (i.e. on each node).
    Note :  However, with sequences in RAC, you have to be careful with the definition.  Have you defined it or do you need to define it as CACHE/NOCACHE ?  Have you defined it or do you need to define it as ORDER (to guarantee order generation in RAC) ?
    Hemant K Chitale

  • Oracle11 Sequence problem

    Hello,
    after moving from Oracle9 to Oracle11 we have found, that there are very big wholes in the ID numbers of one of our tables. The table gets its primary key over "select seq.nextval from dual" and the sequence cache set to 100. This was exactely the same before moving to Oracle11, but we didn't have problems with IDs like now. During one day the sequnse increases by 3000 while there are about 200 new records in the table.
    Please, help.
    Vladimir

    user487111 wrote:
    Yes, we cache sequences. In this case it is 100. This does not explain the difference between Oracle9 and Oracle11. It does not explain the jumps of 300 values either.Why not? If there is sufficient activity in your database maybe the cache got aged out. This could possibly explain large gaps in sequence numbers.
    Example:
    SQL> CREATE SEQUENCE test CACHE 100;
    Sequence created.
    SQL> SELECT test.NEXTVAL FROM DUAL;
                 NEXTVAL
                       1
    SQL> ALTER SYSTEM FLUSH SHARED_POOL;
    System altered.
    SQL> SELECT test.NEXTVAL FROM DUAL;
                 NEXTVAL
                     101

  • Row cache wait in Oracle RAC

    Hi,
    Our application is running on Oracle RAC. During certain time of the day, the applcation responds very slowly. At these times, it is observed that the row cache waits are very high. We have even tried altering the sys.AUDSES$ sequence and changing it cache size to 10000 from default 20, but this did not help.
    Can anyone suggest a solution for this problem? And why this problem occurs?

    Hi,
    it looks like your problem is related to the fact that you do not cache sequences (this is a well know RAC tuning topic).
    Oracle introduced sequences (wrong name, definitely) to generate unique numbers, not to actually support a time sequence of events, or to preserve an order or to have ascending sequences of numbers with no gaps.
    Ordering a sequence of events is a serialization process that should not be implemented by a sequence.
    Now, if you do not cash sequences, in RAC the lock (enqueue) on the sequence (that is required when you ask for the next set of values) is a global resource on which inter instance contention occurs.
    Furthermore, in case the application has a high volume of inserts, having nocache sequences leads to inter instance index block contention.
    Oracle says that the default cache value of 20 for sequences is inappropriate in most case of RAC implementations and it is frequent to have caches of 1000 values or more. You need to test what is your ideal value.
    Now it is up to you to decide between:
    - keep things as they are and have a non scalable RAC installation
    - find a way to cache sequences without harming the application assumptions.
    Hope it helps,
    Regards,
    Corrado

  • HOW TO GET AUTO GENERATED PRIMARY ID KEY BACK FROM AN INSERT STATEMENT IN .

    Just recently I ran into a problem with what seems to be a deficiency in the Oracle Database. When trying to return an auto-generated key as is done in Microsoft's SQL database, it seems Oracle for whatever reason didn't add this capability, the key couldn't be passed back to the .Net call. After tinkering with the .Net software and talking with the Oracle techs, a decent work around to the problem (presented here) comes fairly close. Two things have to be done first before this will work. A sequence has to be created on the Oracle DB. Also a trigger has to be created against the table the keys are going to be returned from.
    The class works by passing to the function 'update_datasets_return' a DataSet with as many tables as you want. The function spins through the tables and put the keys in each row inserted. It's assumed the first row will either be the primary key or some numeric value. This can be changed by modifying the: dt.Columns(0).ColumnName
    Notice the word Inserted. On Updates and Deletes the key value is ignored because it's already present. The routine just updates the database as usual.
    So in other words you could send a table to the function with rows inserted, deleted, or updated and it will take care of them all. One routine for all.
    ' ======================================================================
    ' Created by SEF and Oracle SR: 5607364.993 This is a complete Redo
    ' of the initial concept. SEF...
    ' Sample of sequence and trigger at bottom.
    ' Uses the ODP.NET data provider.
    ' update_datasets_return: Goes thru each table in the dataset and
    ' updates, deletes, or inserts as needed.
    ' If inserting, a 'sequence counter' and a 'trigger'
    ' using the 'before insert' must be present. The sequence
    ' counter is set to auto increment by 1 starting at 1.
    ' The trigger is specific to the table.
    ' Create the trigger and sequence in the database or run the samples
    ' below in PL/SQL. Be sure the logon with a user that has enough rights.
    ' Routine assumes the first column is going to hold the sequence
    ' number. Actually any column could be used. Just change the
    ' dt.Columns(0).ColumnName to whatever you want or leave as default.
    ' The da_RowUpdated sub is where the 'sequence number' gets returned
    ' on each row that is inserted into a table. Routine is ignored on
    ' deletes and updates. SEF...
    ' =======================================================================
    Imports System
    Imports System.Data
    Imports Oracle.DataAccess.Client
    Imports Oracle.DataAccess.Types
    Public Class OracleUpdate
    Private Shared m_conn As OracleConnection
    Private Shared da As New OracleDataAdapter
    Private Shared dt As DataTable
    Private Shared conn As New OracleConnection
    Private Shared dr As DataRow
    Private Shared astep As Long
    Private Shared rwIndex As Integer = 0
    Private Shared tblIndex As Integer = 0
    Public Shared Function update_datasets_return(ByVal constr As String, ByVal ds As DataSet) As DataSet ''ByRef ds As DataSet)
    Dim selectstmt As String
    m_conn = New OracleConnection(constr)
    Try
    m_conn.Open()
    Catch ex As Exception
    Throw New ArgumentException(" Error: connection lost." & ex.Message)
    End Try
    For Each dt In ds.Tables
    ''Uncomment the code only if auto numbering
    ''is NOT turned on for the table being updated. SEF...
    ''rwIndex = 0
    ''For Each dr In dt.Rows
    '' Try
    '' Select Case dr.RowState
    '' Case DataRowState.Added
    '' astep += 1
    '' ' =======================================================
    '' ' This "Try Catch" section created only if auto numbering
    '' ' is NOT turned on for the table being updated. SEF...
    '' ' It's a crude attempt at creating a unique number.
    '' ' A more serious approach would be to use a GUID.
    '' ' Use only if you decide not to have a sequence and a
    '' ' trigger for the table.
    '' ' =======================================================
    '' Try
    '' 'ds.Tables(tblIndex).Rows(rwIndex).Item(0) = astep
    '' Catch
    '' ' ignore the error corrected integer identity so don't randomize it
    '' End Try
    '' dr.Item("createdDate") = Now
    '' dr.Item("changedDate") = Now
    '' Case DataRowState.Modified
    '' dr.Item("changedDate") = Now
    '' End Select
    '' Catch ex As Exception
    '' conn.Close()
    '' conn.Dispose()
    '' Throw New ArgumentException(" Error: update_datasets " & ex.Message)
    '' End Try
    '' rwIndex += 1
    ''Next
    selectstmt = "SELECT * From " & dt.TableName & " Where " & dt.Columns(0).ColumnName & " = " & 0
    da = New OracleDataAdapter(selectstmt, m_conn)
    Dim bldr As OracleCommandBuilder = New OracleCommandBuilder(da)
    AddHandler da.RowUpdated, New Oracle.DataAccess.Client.OracleRowUpdatedEventHandler(AddressOf da_RowUpdated)
    Dim insCmd As OracleCommand = Nothing
    Try
    insCmd = CType(bldr.GetInsertCommand(), OracleCommand)
    Catch ex As Exception
    Throw New Exception("")
    End Try
    insCmd.CommandText += " returning " + dt.Columns(0).ColumnName + " into :seqno"
    insCmd.Parameters.Add(New OracleParameter("seqno", OracleDbType.Int16, _
    4, ParameterDirection.Output, False, CType(0, System.Byte), CType(0, _
    System.Byte), dt.Columns(0).ColumnName, DataRowVersion.Current, Nothing))
    da.InsertCommand = insCmd
    Try
    ' ===========================
    da.Update(ds, dt.TableName)
    ' ===========================
    Catch ex As Exception
    Throw New ArgumentException(" Error: update_datasets_return " & ex.Message)
    End Try
    Next
    m_conn.Close()
    m_conn.Dispose()
    Return ds
    End Function
    Friend Shared Sub da_RowUpdated(ByVal sender As Object, ByVal e As OracleRowUpdatedEventArgs)
    If e.StatementType = StatementType.Insert Then
    e.Row(0) = Int64.Parse(e.Command.Parameters("seqno").Value.ToString())
    End If
    End Sub
    ' ================================================================================
    ' Notes:
    ' =================== How To -- Sample section for PL/SQL ==================================
    ' myTrigger, myTable, mySequence, and myColumn are values you need to supply.
    ' Note: A trigger needs to be created for each table.
    ' A sequence needs to be created only once and referenced each time
    ' in the trigger(s). Or you could create a new sequence each time you
    ' create a trigger. Sort of a waste of effort.
    ' Explanation:
    ' myTrigger = The name you are giving this trigger.
    ' If a trigger with same name already
    ' exist, it will be overwritten.
    ' myTable = Table you want to add the sequence numbers to.
    ' mySequence = Sequence counter you created. Whatever name you called it.
    ' myColumn = The column to update with the sequence number.
    ' =================================================================================
    ' -- Run in PL/SQL or create at DB. --
    ' create or replace trigger myTrigger
    ' before insert on myTable for each row
    ' begin
    ' select mySequence.nextval into :new.myColumn from dual ;
    ' end;
    ' -- Run in PL/SQL or create at DB. --
    ' create sequence mySequence
    ' MINVALUE 1
    ' START WITH 1
    ' INCREMENT BY 1
    ' NOCACHE; can be set to CACHE but sequence may contain gaps.
    ' Explanation of CACHE from: http://www.techonthenet.com/oracle/sequences.php
    ' With respect to a sequence, the CACHE option specifies how many sequence
    ' values will be stored in memory for faster access. The downside of creating
    ' a sequence with a CACHE is that if a system failure occurs, all cached
    ' sequence values that have not be used, will be "lost". This results in
    ' a "gap" in the assigned sequence values. When the system comes back up,
    ' Oracle will CACHE new numbers from where it left off in the sequence,
    ' ignoring the so called "lost" sequence values.
    ' Note: To recover the lost sequence values, you can always execute an
    ' ALTER SEQUENCE command to reset the counter to the correct value.
    ' NOCACHE means that none of the sequence values are stored in memory.
    ' This option may sacrifice some performance, however, you should not encounter
    ' a gap in the assigned sequence values.
    End Class
    C#:
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class OracleUpdater2
    private static OracleConnection m_conn;
    private static OracleDataAdapter da = new OracleDataAdapter();
    private static OracleConnection conn = new OracleConnection();
    public static DataTable load_it(string constr, string strqry, string tblName)
    // =====================================================================
    // constr = User Id=myUser;Password=myPass";Data Source=myDataSource
    // strqry = Select * from something?
    // tblName = The table name to fill.
    // =====================================================================
    conn = new OracleConnection(constr);
    conn.Open();
    da = new OracleDataAdapter(strqry, conn);
    OracleCommandBuilder bldr = new OracleCommandBuilder(da);
    DataTable dt = new DataTable(tblName);
    da.Fill(dt);
    conn.Dispose();
    return dt;
    public static DataSet update_datasets_return(string constr, DataSet ds)
    //'ByRef ds As DataSet)
    string selectstmt = null;
    m_conn = new OracleConnection(constr);
    try
    m_conn.Open();
    catch (Exception ex)
    throw new ArgumentException(" Error: connection lost." + ex.Message);
    foreach (DataTable dt in ds.Tables)
    selectstmt = "SELECT * From " + dt.TableName + " Where " +
    dt.Columns[0].ColumnName + " = " + 0;
    da = new OracleDataAdapter(selectstmt, m_conn);
    OracleCommandBuilder bldr = new OracleCommandBuilder(da);
    da.RowUpdated += new
    Oracle.DataAccess.Client.OracleRowUpdatedEventHandler(da_RowUpdated);
    OracleCommand insCmd = null;
    try
    insCmd = (OracleCommand)(bldr.GetInsertCommand());
    catch (Exception ex)
    throw new Exception("" + ex.Message);
    insCmd.CommandText += " returning " + dt.Columns[0].ColumnName + " into
    :seqno";
    insCmd.Parameters.Add(new OracleParameter("seqno", OracleDbType.Int16, 4,
    ParameterDirection.Output, false, System.Convert.ToByte(0),
    System.Convert.ToByte(0), dt.Columns[0].ColumnName, DataRowVersion.Current,
    null));
    da.InsertCommand = insCmd;
    try
    // ===========================
    da.Update(ds, dt.TableName);
    // ===========================
    catch (Exception ex)
    throw new ArgumentException(" Error: update_datasets_return " +
    ex.Message);
    m_conn.Close();
    m_conn.Dispose();
    return ds;
    If you need a working program of how this works, let me know.

    Oh my god, it is too long! You definitely check out types, casting and especially ODP.Net (it does everything for you)... etc. They can help you to simplify your code. I do not have enough time to copy paste it to Studio and understand and solve your issue, so I got title of your message as your main question.
    In Oracle, you can create an autonumber field by using sequences object. This is really useful when you need to create a unique number to act as a primary key.
    Basically you can create a sequence simply typing;
    CREATE SEQUENCE MY_SEQUENCE;
    now you have a sequence called "MY_SEQUENCE"... Then, I advice you select a number from sequence;
    select MY_SEQUENCE.nextval from dual;
    I said I advice actually kinda must, although it called sequence, I cannot be sequential. Do not even try to predict the value. You can be sure that it is unique number so you can use it.
    Then insert you record and use that number part of your primary key. I think that's it. Have fun.

Maybe you are looking for

  • Cancelled invoice is not posting to FI due to Archived sales order

    Hello Experts, We are trying to post cancelled invoice but getting error message "Business Data 40111265 10". When we checked for this invoice delivery and sales orders are archived. So could you please tell is there any way to post this invoice. If

  • Local Database, TNS Names & ORA-12541: No Listener

    I am trying to get IFS working on our new Windows 7 machine and the entire department is scratching it's head right now. I have gotten Oracle 11.2.0.1 installed and finally being seen by the ODBC thanks to the past threads on the forum mentioning the

  • The 'Third Party Connections' drop down box on the 'Source Database' step in the Migration Wizard is empty.

    Here are the environmental details:   SQLDeveloper 32-bit Version 3.2.20.09 (Build MAIN-09.87) Oracle Database:  12C single instance (no RAC) Oracle client:  12C 32 bit Windows 64 bit desktop I am attempting to migrate an MS Access application to Ora

  • Cannot publish to Breeze

    Hi all - I was hoping that one of you could lend me some expertise. I am trying to publish a Captivate (ver 1.1) quiz to a Breeze server - it consists of regular question slides and interactive slides. I can preview the file okay. But when I try and

  • Regarding ADS Authentication

    Hi, We are developing application using weblogic workshop8.1 with integration domain. Let me explain the scenario and requirement. We need to use ADS for storing and authenticating users. In admin console, defaultauthenticator under security.Realms.m