Sequence get the last value (or store the .NEXTVAL anywhere)

Hi there,
I created some tables and one table references the other (foreign key).
Now I want to add some test data and insert rows to both tables.
My problem is:
The "insert into command" for table a uses a sequence value to create the primary key. Now I need the assigned primary key in my second insert command to assign the right value to the foreign key.
Is there a way to get the last assigned value from a sequence? Or can I store the key to some sort of variable and use this in both statements?
Thx a lot
Dominik

Is there a way to get the last assigned value
from a sequence?
NEXTVAL return next available value in the sequence.
If you want last returned value you need to use
CURRVAL instead.
>SELECT <your_sequence>.CURRVAL from dual;Peter D.Currval not work always, read the following example :
Re: auto generating primary key
Nicolas.

Similar Messages

  • How can I return the nextval of a particular sequence from a stored procedure?

    I have a stored procedure that basically generates and records
    nextval into a table each time the procedure is called. I want
    to return this value in an out parameter. Is this possible? If
    so, how do I implement it?

    sq> create sequence s1 start with 1 increment by 1;
    procedure to get the nextval from a sequence:
    sql>create or replace procedure p1
    (seq_no_p OUT Number)
    is
    Begin
    select s1.nextval into seq_no_p from dual;
    End p1;
    to call the above procedure to get the out parameter(nextval):
    declare
    p number;
    begin
    p1(p);
    end;
    If this is what u want.
    Thiru

  • Unable to get the "Alerts" in the bi dashboard

    Hi experts,
    I am using Oracle business intelligence standard edition one version, I am using Delivers to send Email. I did all the configuration successfully and I am able send the email. But unable to get the "Alerts" anywhere in the dashboard after clicking save in Delivers.
    Please help me to how to bring the "Alerts" highlighted in the BI Dashboard.
    Regards,
    Raj

    How about permission on Admin> Previlages > Manage Previlages > delivers make sure it for everyone
    Also make sure you have _Delivers folder.
    In order to get a list of all the ibots that are sent to you(Interactive Dashboard should be part of your Active Delivery Profile) create a section in your Dashboard and rename that section as _Delivers. That will show all the list of ibots.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to get the values enterd in the interactive form and store it in table.

    Hi Experts,
    I have a requirement, i want to display the editable fields in Adobe form and have a button.If i click the button what i enter in the fields that will be store in the table.
    I tried but the button action is not going....
    In the Form i put the layout type as : xACFLayout.
    and in the webdynpro the enabled property checked and display type put the activeX still the form in the fields are in non-editable....
    Can you please give me step by step procedure for the same.
    Thank you in advacne..
    Thanks.
    Rrrr.

    Hi,
    I put the form layout is ZCI.
    When i click the button the acion was not trigerring.
    Please help me in this ASAP. It's imp for me..
    For your understand;
    My Requirement:
    I have a interactive form in that 2 input fields 1. First name 2.Last name and one button .
    If i clcik the button what i enterd in the above 2 inputfields i have to get store it in R/3 table.
    I tried this one.
    1. Created the view in the context created the node "adobe" cardinality... (1..1) and below created the child node "input" cardinality(1..1) and 2 attributes first name and last name.and other attribute pdfsource type xstring.
    created the UI element Interactive form, and chekc the enabled checkbox, and display type "native" and binding the  data source property to node  "adobe" cardinality... (1..1) and pdf source to pdfsource node. and templet  gave  "ZFORM" and gave the interface name "ZINTERFACE" and drag and drop the node elements into layout
    and created the webdybnpro button and webdynpro event gave *clcik and javascript and save activated the form.
    2. In the Ui elemt in view action onsubmit wrote the code to get the context element values and insert  that int0o table.
    But here the Submit button action was not trigerring.....................
    can you please help me in the same..... ASAP give any sugesstion what i have to change in this scenario.....

  • 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

  • JTable problem : how to get the last value entered by user + event lost

    Hi all,
    I have 2 problems with Jtable class.
    1 => To get the last value entered by user in a cell,
    it seems that we must change the selected cell.
    That is to say we can only have the previous cell's value.
    Is there a simple way to get the current value of any cell ?
    2 => To resolve the problem i store the values of each cell in a vector and i intercept keyboard event (!)
    BUT, when i do a double click with the mouse on the Jtable, i loose keyboard events. Then, i can't intercept them.
    Is it a bug of swing or am i following a wrong way ?
    Thanks by anticipation for your help.

    You have to fire the "TableCellUpdatedEvent"
    and override the getCellEditorValue in TableCellEditor to return the current value

  • Inserting sequence value from JDBC and getting the same value back

    Hi: Gurus I have a table whose primary key is a sequence. I wonder how to make sure I get the same sequence value back for current transaction so I update the other table whose foreign key is the sequence value from first table.
    E.g lets say I do this
    String query_insert = INSERT INTO table1 (column1, ....) VALUES (HIGHLIGHT_ID_SEQ.nextval, ...);
    pstmt = con.prepareStatement(query_insert);
    pstmt.executeUpdate();
    How I make sure no other transaction update the sequence value so I can read the last inserted sequence value and update the second table with this value
    String query_select = "SELECT HIGHLIGHT_ID_SEQ.currval FROM DUAL";
    pstmt = con.prepareStatement(query_select);
    Regards,
    Rashid.

    <rant>No version again. I wonder why people requiring help want to stay anonymous and never want to type their version, only 4 digits. In this case, jdbc, not only the version of the driver is important, but also it's type. Waving a magic wand again? </rant>
    Look up the returning into clause of the insert statement in the sql reference manual for your version.
    Sybrand Bakker
    Senior Oracle DBA

  • How to get the last value edited by users from JTable?

    Hi.
    I have a JDialog that includes an editable JTable. This table is used to set up field caption and font for a report program. I found only when cursor is moved to another cell, the value in current cell being edited will be transferred to Table Model. So if the user don�t move cursor to another cell after editing the value of a cell but click OK button directly, Table Model cannot get the last value edited by the user, I wonder if there is a way to fire JTable to transfer the value being edited to Table model.
    By the way, I found if the TableCellEditor is using JCheckBox or JComboBox instead of JTextField, there is no this problem.
    Thank you for any reply.

    I guess you can make use of the following methods on your table model to inform it make it getValueAt bcos table data has changed.
    fireTableCellUpdated
    Notifies all listeners that the value of the cell at [row, column] has been updated.
    fireTableChanged
    Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
    fireTableDataChanged
    Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same.
    But when to call these methods??
    -- When OK button is pressed, do this as the first thing!!
    OR
    -- Call this on every key event!!
    regds,
    CA

  • How to get the last inserted Autoincrement value in Java for Pervasive DB

    Hi, I need to get the last inserted auto incremented value after the record is inserted IN JAVA For ex. consider we have 4 columns for the myTable in the PERVASIVE DATABASE V10 autoid - identity column (auto increment column) userID userName pageID insertSqlExpression = insert into myTable (userID , userName, pageID) values( ? ,? ,?); prepareInsert = connection.prepareStatement(insertSqlExpression); prepareInsert .excuteUpdate; After inserting the new record how can I get the autoid value (last inserted value) in the Java. Please help me.
    Thanks in advance. Arthik

    JavaArthikBabu wrote:
    I dont have privileges to write new stored procedures in database.I need to do in the Java side only. In many databases that irrelevant. The same way you would do it in a proc can be done with the correctly conceived statement (singular.)
    For ex &#150; if we insert and then the select record's identity value as a single transaction and would this guarantee that what is returned by the select would not include inserts that another might have made?Please do not take that path unless you are absolutely certain that your database does not support any other way to do it.

  • How to get the sales value of the last month in the quarter

    Hi,
    We have a requirement to get the "Sales" value against a quarter. We have 2 tables "Time" and "Sales". We want to display the Sales value against each quarter.
    But this should happen as follows.
    Consider quarter Q1 it should display the value of 3rd month, Q2 should display value for 6th month and so on..
    If in any particular Quarter we dont have a value for last month then it should display the value for 2nd month, if 2nd month value is also not present then it should display 1st month sales value.
    We are using excel as the database.
    Please let us know if anybody has a resolution to this.
    Regards,
    Apoorv Chitre

    hi,make an other column which will be the flag for the last months you want to be displayed...
    so ,in reports,you pass it as hidden column(by filter only the ones which have the appropriate flag),and then voila...
    i hope i helped
    http://greekoraclebi.blogspot.com/
    ///////////////////////////////////////

  • Get the table or view where categorie's sequence order is store

    Hi,
    I manage to display some categories on a page. Some how I like to display the categories in a specific order. To be exact, I like to have the same order as we can define in the pagegroup properties > configure tab > Types and Classification > Categories section, when adding new categories.
    Portal stores that sequence order somewhere because when we return to pagegroup properties we have the same order as defined previously. I looked the Portal's tables and package trying get the table or view where sequence order is stored, but I can't get it.
    Anybody knows where I should get this sequence order? (table or view). I'm new to Portal and so I know little about it.
    Regards

    Here is the query to get the categories in the same order as specified for a page group :
    SELECT wwv_topics.title
    FROM wwv_topics,
    wwsbr_site_category$
    WHERE wwv_topics.id = wwsbr_site_category$.CATEGORY_ID
    AND wwv_topics.siteid = wwsbr_site_category$.CATEGORY_siteID
    AND wwv_topics.language = -- the language desired (eg frc)
    AND wwv_topics.siteid = -- the page group desired (eg 139)
    ORDER BY wwsbr_site_category$.id ASC
    David

  • Compare a column with the another table coulmn(which contains the sequence) and get the value which has higher sequence

    Hi All,
    I have 2 tables 
    table1: col1 sequenceid, col2 code
    table2:col1 studentID , col2 code, col3 joindate
    in table 1 i have values as 
    1 Q
    2 W
    3 E
    4 R
    5 T
    6 Y
    Table2:
    A1 Q 
    1-04-2015
    A1 W
    2-04-2015
    A3 Q 
    1-04-2015
    A2 Q 
    1-04-2015
    A3 W
    2-04-2015
    A2 W
    2-04-2015
    A2  E
    2-04-2015
    A3  E
    2-04-2015
    A1  E
    2-04-2015
    A2  R
    2-04-2015
    Now i want ouput as 
    A3 E
    A2 R
    A1 E
    I want to group the values in table2 based on studentid order by the sequence in the table1 and get the latest which is having higher sequence (Note: the date field cannot be used to order the values)

    from @table2 a inner join @table1 b on a.col2=b.col2 collate database_default)
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • JTable: How to get the last value entered ?

    I have a JTable, with 2 columns and 3 rows that I need to fill..
    If I don't press the Enter key after filling each cell, and if I call the foloowing method
    void readTable()
          String[][] myarray = new String[3][2]; 
           for (int i = 0 ; i<3;i++)
            for (j=0 ; j<2; j++)
             myrray[i][j]  = (String) table.getValueAt(i, j);
    }the last returned value is null.
    Is it possible to simulate the Enter key by program (or any other way) to make sure to get the last edited cell value, whether or not the user press the enter key before clicking on a button (for example) to execute the above code. ?
    Thanks a lot for help
    Gege

    Thanks Camikr, using
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);works fine. It's exactly what I was looking for.
    Thanks again.
    Gege

  • How do I get the last or maximum value /

    Hi all,
    I got the following query output :-
    ITEM_______DATE____________PRICE
    AAA_______01/11/04__________2.5
    AAA_______22/04/05__________4.0
    BBB_______04/08/05__________44
    BBB_______05/08/05__________45
    CCC_______04/12/04__________12
    CCC_______05/05/05__________90
    I want to get the output of the last date, I'm try to use max(date), however, b'cos of the diff price the records still show. I just need the output of the last date, output will be something like below :-
    ITEM_______DATE____________PRICE
    AAA_______22/04/05__________4.0
    BBB_______05/08/05__________45
    CCC_______05/05/05__________90
    How should I code ?
    Rgds
    Lim

    SQL> drop table test_data
      2  /
    drop table test_data
    ERROR at line 1:
    ORA-00942: table or view does not exist
    SQL> create table test_data
      2  (item       varchar2(32)
      3  ,item_date  date
      4  ,price      number)
      5  /
    Table created.
    SQL>
    SQL> insert into test_Data values('AAA', to_Date('01/11/04', 'dd/mm/yy'),2.5)
      2  /
    1 row created.
    SQL> insert into test_Data values('AAA', to_Date('22/04/05', 'dd/mm/yy'),4.0)
      2  /
    1 row created.
    SQL> insert into test_Data values('BBB', to_Date('04/08/05', 'dd/mm/yy'),44)
      2  /
    1 row created.
    SQL> insert into test_Data values('BBB', to_Date('05/08/05', 'dd/mm/yy'),45)
      2  /
    1 row created.
    SQL> insert into test_Data values('CCC', to_Date('04/12/04', 'dd/mm/yy'),12)
      2  /
    1 row created.
    SQL> insert into test_Data values('CCC', to_Date('05/05/05', 'dd/mm/yy'),90)
      2  /
    1 row created.
    SQL>
    SQL> select * from test_Data
      2  /
    ITEM                             ITEM_DATE      PRICE                                              
    AAA                              01-NOV-04        2.5                                              
    AAA                              22-APR-05          4                                              
    BBB                              04-AUG-05         44                                              
    BBB                              05-AUG-05         45                                              
    CCC                              04-DEC-04         12                                              
    CCC                              05-MAY-05         90                                              
    6 rows selected.
    SQL>
    SQL> select * from test_data
      2  where (item_date, item) in
      3  (select max(item_date) item_date, item from test_Data group by item)
      4  /
    ITEM                             ITEM_DATE      PRICE                                              
    AAA                              22-APR-05          4                                              
    CCC                              05-MAY-05         90                                              
    BBB                              05-AUG-05         45                                              

  • Getting the last selected value of the combo  - very very urgent...........

    On my panel i have a jcombobox in upper half(which displays say the address type.) and few text fields on the lower half(which displays the add details). when the user selects a value in the combo box the text fields are populated based on the selection. The user can change the values displayed in the text fields. So before setting the new values in the text fields the last displayed values need to be saved.
    I have an ActionListener for my combo which gives me the currently selected value by calling getSelecetdItem()
    How can i get the last selcted value of the combobox without using any variable of my own.

    To update the last displayed details(the address details say) i need to check what type of address the combo had previousely.....
    when i display the panel first time the home address is set by default and i have a variable to hold this value..as the user changes the selection i update the variable...I don't want to use this variable..instead if i can get the last selcted value from the event that would be great...
    thanks

Maybe you are looking for