Retrieve the sequence number just used in the insert

Hi All, is there a way to use the sequence.nextval for an insert and return the sequence value in one call?
We need to port our application from MS SQLServer to Oracle. The tables in SQLServer have Identity columns as the primary key. We can do the insert and retrieve the identity column value with one call to the database. I wonder if we can do the similar thing with Oracle.
I found out that there is a "returning into" clause for an insert statement that can return information on the current row, something like: insert into tbl (id, name) values (seq.nextval, 'name') returning id into my_id. I can't get the above query to work.
Any help is greatly appreciated.
Xiaoyun

Hi Tim,
To avoid this problem you can do one thing. If you are quering the database from java, place both the commands in a synchronised block as follows:
synchronized(this){
This will allow only one user to enter the block and hence helps to retrieve the same value.
The same procedure is followed in Survey Sample located at
http://otn.oracle.com/sample_code/tech/xml/xmldb/content.html
Have a look at that. Check the saveChoiceGroups method in ChoiceGroupCache.java
Regards,
Anupama

Similar Messages

  • Unified CCX Editor: Retrieving Sequence Number on Multi-Leg Call

    Hi
    I'm fairly new to scripting in the Unified CCX Editor, so apologies for any mistakes/misunderstandings I may have.
    I have a situation where I'm trying to retrieve and use the Sequence Number of a call within a script.
    There is a tool called "Get Contact Info" where you can retrieve the Sequence Number from the session, but this does not work for calls with more than 1 leg.
    e.g. I have an incoming call which is answered by Agent A, who then transfers the call to a seperate queue where it is answered by Agent B.
    This creates 2 records in ContactCallDetail (and other related tables) with the same Session Id, but a sessionSeqNum of 0 for the first leg, and 1 for the second leg.
    Within the script for the 2nd queue, I'm retrieving this sequence number and populating one of the Custom Variables's with it, so that I can confirm that the value is correct.  It is not!  It is always set to 0 (even if the default for the variable I'm pulling the Get Contact Info->Sequence Number into has a default value of 999.
    So, how do I get the Sequence Number?
    Any ideas?
    Thanks
    Liffey

    Hi,
    I test using the "select ressource" box, that way I am using a CSQ and it's works. Before, I was just testing with a "Redirect call" box and that is not the right solution.
    Thank you
    H.C

  • How to retrieve the last inserted row

    This may be a question with a very known answer but I couldn't find any within this forum.
    What is the proper way to retrieve the just inserted record ?
    I'm accessing the DB from external Java and at this moment I use a timestamp column in order to retrieve the inserted row. So I generate an unique timestamp ('20020615184524356') which I inserted during the insert operation. I retrieve the just inserted row using "select * from fooTable where(timestamp='20020615184524356')".
    Is this the general idea or am I totally wrong ?

    hi Shaik Khaleel,
    Just wanted to clarify my doubts regarding rowid.
    Please refer the subject as "abt rowid" in previous posting and ur reply for that was
    "its an unique number throughout the database, its an hexadecimal number. it assigns the rowid of the deleted row in future , but not to the immediate insertation row."
    As u have mentioned the rowid of the deleted row can be assigned to a new row in future,
    wont the following query fail.
    select * from temp where rowid=(select max(rowid) from temp); -- in oracle. ~chandru

  • Sequence number in process order

    Hi,
    Kindly brief about usage of sequence number, which is in process order with example. Is this can be used for capacity leveling. If so how that can be done.
    If one sequence number is assigned to multiple process orders means double entries, then what is the impact during capacity leveling based sequence number.
    Is number range is maintained any where in SPRO for sequence number. If so where? Is there any possibility to maintain number range for sequence number if required?
    Thanks & Regards,
    N. Laxman

    1.Seq. number in an order
    Number that can be assigned to production orders or planned orders at the level of the task list header and is therefore valid for all the operations in an order.
    The sequence number is used to  sort the orders for the display on the planning table and to
    form a dispatching sequence using the sort key.
    3.

  • Sequence number different in DB than from assignSequenceNumber()

    I am using TopLink 10.1.3 DP4 (I think - inside JDev build 3565). I am attempting to use a sequence in a schema that I DO NOT OWN - I cannot make modifications tot he database sequence because there are other applications in place running against it.
    The database sequence is in a 10g database, with an interval of 1 and a cache of 20.
    My object uses the value of the sequence as the sole element of its primary key. I am creating a new object, registering it with a UnitOfWork using registerNewObject(obj). It seems that this does not make a clone, since the object returned by this method is the same identity as the object passed in.
    My project sequencing policy is set as follows:
    <project-sequencing-policy>
    <sequencing-policy>
    <preallocation-size>1</preallocation-size>
    <sequencing-type>Use native sequencing</sequencing-type>
    <name-field-handle>
    <field-handle/>
    </name-field-handle>
    <counter-field-handle>
    <field-handle/>
    </counter-field-handle>
    <sequencing-policy-table></sequencing-policy-table>
    </sequencing-policy>
    </project-sequencing-policy>
    Platform is 10g
    <platform-name>Oracle10g</platform-name>
    The sequence is accessed through a synonym (since JDev couldn't seem to reference a sequence in a different schema from a user's login).
    <sequence-number-name>EVENT_SEQ_SYN</sequence-number-name>
    <uses-sequencing>true</uses-sequencing>
    When I commit my new object, I can see the insert statements in the log claiming a value of 'x' for the primary key. The row in the database actually has a primary key of 'y', where 'x = y - preallocation size' and 'y = sequence last number - preallocation size'. I think I would get the right number if I could set the preallocation size to 0 (performance problems understood) but TopLink chokes on this at run-time.
    Is this problem familiar to anyone?
    Failing using native sequencing, I tried to write custom SQL for the insert statement, but I couldn't find any decent examples anywere on how to do that. I found in a deep google search an example that showed you could use hash (#) to reference the value of a property, but what if the value that needs to be inserted in the database is held in an indirect referenced object? For example, if I was trying to write an insert sql for a Pet object with an indirect reference (valueHolder) to its owner, and I needed to put the owner id in the row - how would I write that insert statement in the 'custom sql' pane in workbench?
    Thanks for your help.
    Dave

    Very strange case.
    I tried to reproduce it using TopLink Employee example - and couldn't.
    Here's the code:
        //  to get debug info
        session.setLogLevel(SessionLog.ALL);
        session.login();
        UnitOfWork uow = session.acquireUnitOfWork();
        Employee emp = new Employee();
        emp.setFirstName("sequencingTest");
        uow.registerNewObject(emp);
        uow.assignSequenceNumber(emp);
        uow.commit();
        System.out.println("firstName = "+emp.getFirstName() +"; id="+ emp.getId());And here's the log:
    [TopLink Info]: 2006.01.26 04:49:05.734--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--TopLink, version: Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060116)
    [TopLink Config]: 2006.01.26 04:49:06.171--DatabaseSessionImpl(18)--Connection(19)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
         platform=>Oracle9Platform
         user name=> "test"
         datasource URL=> "jdbc:oracle:thin:@localhost:1521:orcl"
    [TopLink Config]: 2006.01.26 04:49:10.140--DatabaseSessionImpl(18)--Connection(39)--Thread(Thread[main,5,main])--Connected: jdbc:oracle:thin:@localhost:1521:orcl
         User: TEST
         Database: Oracle Version: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
         Driver: Oracle JDBC driver Version: 10.1.0.4.0
    [TopLink Finest]: 2006.01.26 04:49:10.625--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--sequencing connected, state is Preallocation_NoTransaction_State
    [TopLink Finest]: 2006.01.26 04:49:10.718--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--sequence PROJ_SEQ: preallocation size 1
    [TopLink Finest]: 2006.01.26 04:49:10.718--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--sequence ADDRESS_SEQ: preallocation size 1
    [TopLink Finest]: 2006.01.26 04:49:10.718--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--sequence EMP_SEQ: preallocation size 1
    [TopLink Info]: 2006.01.26 04:49:11.453--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])-- login successful
    [TopLink Finer]: 2006.01.26 04:49:11.703--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--acquire unit of work: 48
    [TopLink Finest]: 2006.01.26 04:49:11.703--UnitOfWork(48)--Thread(Thread[main,5,main])--Register the new container bean Employee: sequencingTest
    [TopLink Finest]: 2006.01.26 04:49:11.734--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--Execute query ValueReadQuery()
    [TopLink Fine]: 2006.01.26 04:49:11.750--DatabaseSessionImpl(18)--Connection(39)--Thread(Thread[main,5,main])--SELECT EMP_SEQ.NEXTVAL FROM DUAL
    [TopLink Finest]: 2006.01.26 04:49:12.328--DatabaseSessionImpl(18)--Thread(Thread[main,5,main])--sequencing preallocation for EMP_SEQ: objects: 1 , first: 3,469, last: 3,469
    [TopLink Finest]: 2006.01.26 04:49:12.328--UnitOfWork(48)--Thread(Thread[main,5,main])--assign sequence to the object (3,469 -> Employee: sequencingTest )
    [TopLink Finer]: 2006.01.26 04:49:12.328--UnitOfWork(48)--Thread(Thread[main,5,main])--begin unit of work commit
    [TopLink Finer]: 2006.01.26 04:49:12.421--DatabaseSessionImpl(18)--Connection(39)--Thread(Thread[main,5,main])--begin transaction
    [TopLink Finest]: 2006.01.26 04:49:12.437--UnitOfWork(48)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(Employee: sequencingTest )
    [TopLink Finest]: 2006.01.26 04:49:12.625--UnitOfWork(48)--Thread(Thread[main,5,main])--Assign return row DatabaseRecord(
         EMPLOYEE.VERSION => 1)
    [TopLink Fine]: 2006.01.26 04:49:12.625--UnitOfWork(48)--Connection(39)--Thread(Thread[main,5,main])--INSERT INTO EMPLOYEE (EMP_ID, L_NAME, F_NAME, GENDER, END_DATE, START_DATE, MANAGER_ID, START_TIME, END_TIME, ADDR_ID, VERSION) VALUES (3469, NULL, 'sequencingTest', NULL, NULL, NULL, NULL, {t '09:00:00'}, {t '17:00:00'}, NULL, 1)
    [TopLink Fine]: 2006.01.26 04:49:12.640--UnitOfWork(48)--Connection(39)--Thread(Thread[main,5,main])--INSERT INTO SALARY (SALARY, EMP_ID) VALUES (0, 3469)
    [TopLink Finer]: 2006.01.26 04:49:12.781--DatabaseSessionImpl(18)--Connection(39)--Thread(Thread[main,5,main])--commit transaction
    [TopLink Finer]: 2006.01.26 04:49:12.796--UnitOfWork(48)--Thread(Thread[main,5,main])--end unit of work commit
    [TopLink Finer]: 2006.01.26 04:49:12.796--UnitOfWork(48)--Thread(Thread[main,5,main])--release unit of work
    firstName = sequencingTest; id=3469
    If I understood correctly, the problem is x showing up in insert as a value to be assigned to PK and y actually inserted into the db. If that's the case could there be a BeforeInsert trigger on the table? To test try inserting through jdbc using concrete pk value.

  • Lightroom export sequence number automatic increment and update

    I'm exporting to hard disk using the name-sequencenumber option. When exporting multiple times, Lightroom does not seem to remember what sequence number it last used. Is there a configuration option somewhere to let Lightroom keep track of the sequence numbers used? For example, I have a set of 20 photos that I export. I set the name to X and the sequence number to 1000. So, the first export adds them to my destination folder numbers X-1000 through X-1019. Now, I import another batch of say 30 photos. When I go to export those, I get a warning that there are duplicate file names since Lightroom is starting over at 1000 again instead of 1020. I don't want to enter a new sequence number every time I export. Is there a way for Lightroom to remember the last sequence number it used?

    AFAIK, you have to enter the sequence number with every export.

  • I aGenerating a Sequence Number within a String

    Hi folks,
    I am trying to create a control file which I would be using for load records using SQL*Loader. I need to generate the Sequence Number and use the value for the column REQ_NUM. I have a file TEST.TXT which contains 30 records with STUDENT_ID. I would like to create a control file because I want to load all 30 rows with the same REQ_NUM.
    Here is what I have but I need to get the value of the Sequence Number.
    spool testing.ctl
    'load data infile 'TEST.TXT'
    select
    'append into table DUMMY_TABLE
    FIELDS TERMINATED BY '','' optionally enclosed by ''"''
    trailing nullcols
    (req_num CONSTANT "select req_num_seq.nextval from dual",
    student_id)'
    from   dual;
    spool off;
    exit 0;
    {code}
    Any help is greatly appreciated. I am on Oracle 9i.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sorry to have made this complicated but all I want to do is my output of the SQL as something like this.
    Now, I have a Sequence out there that I was planning on using. Assuming that the Sequence is currently at 362, so when I run the SQL, I should get this output below. Makes sense ?
    append into TEST_TABLE                                                                                                        
    FIELDS TERMINATED BY ',' optionally enclosed by '"'                                                                           
    trailing nullcols                                                                                                             
    (req CONSTANT '363',                                                                                                          
    student_id)
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How can we generate auto Sequence Number in DFF attribute

    Dear
    We are on r12,rignt now we have an issue to generate sequence number in site Level(DFF) on Supplier window,actully we want
    to generate sequence number on site leve while inserting new record on site level,so how could i achvie this or any way which can help us.
    --thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You can consider writing a before-insert trigger.
    The trigger generates the next value of the sequence and makes :new.attributen = the sequence value.
    Hope this helps,
    Sandeep Gandhi

  • I would like to put Dreamweaver 8 on a new computer.  There is no "deactivate" function and the technical support person I chatted with recommended I come here.  Can I just use the serial number again?  How can I deactive?  Has anyone else run into this?

      There is no "deactivate" function and the technical support person I chatted with recommended I come here.  Can I just use the serial number again?  How can I deactive?  Has anyone else run into this?  How can I get Dreamweaver 8, which is no longer being activated by Adobe, on a new computer?  Is it even worth doing or do I need to get a new version.  What are the killer features I'm missing?

    If you manage to get it installed on your current OS, don't forget to install the 8.02 update.
    Adobe - Dreamweaver Support Center : Updaters
    Nancy O.

  • Just got an e mail to say that my Apple ID was just used to download photoshop touch for phone for 2.99 from the App Store with a receipt number. Is this a scam for me to give my Apple ID?

    Just got an e mail to say that my Apple ID was just used to download photoshop touch for phone for 2.99 from the App Store with a receipt number. Is this a scam for me to give my Apple ID?

    No but there's a link to reset your password. Etc etc..
    This is the email I got.
    "Your Apple ID was just used to download Photoshop Touch for phone £2.99 from the App Store on a computer or device that had not previously been associated with that Apple ID.
    If you initiated this download, you can disregard this email. It was only sent to alert you in case you did not initiate the download yourself.
    If you did not initiate this download, we recommend that you go to iforgot.apple.com to change your password, then see Apple ID: Tips for protecting the security of your account for further assistance.
    Regards,
    Apple"

  • Any SAP standard report is used to retrieve the inventory number based Asse

    Hi all
    Any SAP standard report is used to retrieve the inventory number based Asset ID.
    Please help us to provide the standard report.
    Regards
    K.Gunasekar

    Hi,
    Create the Sort version with field Inventory no, so that you can display Inventory no details in all Asset report.
    You can get "Inventory no" details by including field "INVNR" in Sort versions for Asset reporting(T.code - OAVI).
    Hope this information helpful for you.
    Thanks & Best Regards,
    M.Ganesan

  • HT1349 i lost my iphone... if somebody use it my i phone with different apple ID, Do apple company can determine the apple ID used on my iphone serial number?? If i gave my serial number, can it retrieve the apple ID user???

    i lost my iphone... if somebody use it my i phone with different apple ID, Do apple company can determine the apple ID used on my iphone serial number?? If i gave my serial number, can it retrieve the apple ID user???

    No! Apple is not law enforcement and therefore does not have personal investigating lost or stolen property other than Apple's own.
    Even if they had the information data protection laws would prevent them from giving it to you or anybody else including law enforcement.

  • Need to query the database to get the last sequence number

    Hi all
    I am trying to get the last sequence number of the last row inserted into my Oracle database. Please could someone give me the SQL which would allow me to do this - using Oracle SQL Explorer I have confirmed that there is a sequence on the table which is called: XYZ_SEQ and the code for this is:
    CREATE SEQUENCE "MY_USER_NAME"."XYZ_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE ;
    My Java application is inserting a row into my table and to insert a new row I need to have the last sequence inserted +1 so the new row can be added.
    Any help would be much appreciated.

    Hi,
    Welcome to the forum!
    If you are using a sequence just do (example):
    INSERT INTO TABLE_NAME
       (COL1,
        COL2)
    VALUES
       (SEQUENCE_NAME.NEXTVAL,
        OTHER_VALUE);to obtain (and use) the next number in the sequence when you are inserting.
    If you have a sequence to use for a specific table, you should use it when your insert new data (no matter your are doing that: java application, procedure, etc). Doing this you avoid some problems when you have the sequence 'out of date' about the associated data.
    Regards,
    Edited by: Walter Fernández on Sep 19, 2009 10:08 AM
    Edited by: Walter Fernández on Sep 19, 2009 10:10 AM

  • Multiple email addresses against Vendor. What is the ID / sequence number?

    We have a particular vendor with multiple e-mail addresses. These can be viewed via XK03, looking at the address details of the vendor and expanding the e-mail address.
    What I see for one particular vendor are two lines, each with a different e-mail address.
    Line one has a radio button (standard number) selected, has some text saying ' Remittance advice' and an ID of 001.
    Line two has a radio button unselected, has text saying 'PO' and an ID of 002.
    The problem that we have is that when PO's are e-mailed it sends it to the e-mail address on line 1 rather than line 2. Obviously this ID/sequence number is configured somewhere and I assume that the PO's somehow need to told to use ID 002 instead of 001, but where is this defined?.
    Jas

    SAP takes the email adress (fax number) that has the radio button for standard default.
    The text  ' Remittance advice'  is just a note which does not control anything, especially not that this one is taken for the  ' Remittance advice'  only and all others would use the second mail adress.
    If you want it different, then you have to code this yourself in an exit.

  • Query to retrieve the number of transactions done in every 1 hour for last

    Hi,
    Could anyone help in writing a query to retrieve the number of transactions done in every 1 hour for last month.
    Case:
    I/P
    Cases Timestamp1
    case1 01-01-2008 00:00:01
    case2 01-01-2008 00:01:01
    case3 01-01-2008 01:00:01
    case1 01-01-2008 01:02:01
    case4 01-01-2008 01:10:01
    case5 02-01-2008 02:00:01
    case6 02-01-2008 02:10:01
    case7 02-01-2008 23:00:01
    case.. 31-01-2008 24:00:00
    O/P
    from time to_time cases
    01-01-2008 00:00:00 01-01-2008 01:00:00 2
    01-01-2008 01:00:01 01-01-2008 02:00:00 3
    etc
    Any help really appreciated

    We can do this using analytical functions
    Following is what I did:
    create table timestamp1 (ts date)
    select *from timestamp1
    30/10/2008 15:41:13
    30/10/2008 15:41:05
    30/10/2008 15:40:03
    30/10/2008 14:58:26
    30/10/2008 14:29:45
    30/10/2008 13:17:48
    30/10/2008 08:29:50
    30/10/2008 06:05:51
    30/10/2008 03:41:52
    30/10/2008 02:29:54
    select distinct to_char(ts,'hh24') frmhrs,
    to_char(ts,'hh24')+1 tohrs, count(ts) OVER (order by to_number(to_char(ts,'hh24')) RANGE (1/24) PRECEDING )
    from timestamp1
    where trunc(ts)=trunc(sysdate) -- I added this just to make sure I get for today's data
    order by frmhrs
    FRMHRS     TOHRS     CNT
    02     3     1
    03     4     1
    06     7     1
    08     9     1
    13     14     1
    14     15     2
    15     16     3
    You can customizeas per ur need.

Maybe you are looking for