Insert multiple rows in on table and retreive sequence values

Hello,
I'm searching a way to insert several rows in a table that needs a sequence and retreive its.
For one row i use ExecuteScalar method with the following SQL is :
INSERT INTO MY_TABLE(MY_PK)
VALUES(SEQ_MY_TABLE.NEXTVAL) RETURNING MY_PK INTO :MY_PARAMETER
The aim is to insert several rows at one time. Currently I execute this SQL :
INSERT INTO MY_TABLE(MY_PK, MY_VALUE)
SELECT SEQ_MY_TABLE.NEXTVAL, MY_VALUE
FROM (
SELECT 0 MY_VALUE FROM DUAL UNION ALL
SELECT 1 MY_VALUE FROM DUAL
This query works well but i'm wondering how to retreive all sequence values generated by this query.
Is it possible and how ?
Thank you.
Sebastien

I tried this :
string sql = "INSERT INTO MY_TABLE(MY_PK, MY_VALUE) " +
"SELECT SEQ_MY_TABLE.NEXTVAL MY_PK, MY_VALUE FROM ( " +
"SELECT 0 MY_VALUE UNION ALL " +
"SELECT 1 MY_VALUE) " +
"RETURNING MY_PK BULL COLLECT INTO : RETURN_IDS";
using(var manager = myFactory.CreateDbManager()) // Initializes the connection and encapsulates ADO objects
manager.SetCommand(sql);
var cmd = (OracleCommand)manager.Command;
cmd.ArrayBindCount = 2;
var p = new OracleParameter();
p.DbType = DbType.Int64;
p.ParameterName = "RETURN_IDS";
p.Direction = ParameterDirection.Output;
p.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p.Size = 2*sizeof (long);
cmd.Parameters.Add(p);
cmd.ExecuteNonQuery();
var result = (Oracle.DataAccess.Types.OracleDecimal[])p.Value;
But I have an error ORA-00933 that indicates that the query is wrong at "RETURNING MY_PK".
.......................................................................................................^
Edited by: CITnDev on 1 août 2012 13:00
Edited by: CITnDev on 1 août 2012 15:10

Similar Messages

  • Inserting Multiple Rows in a table

    Hello,
    I need to insert multiple rows in a table with the selected items from a list (Multiple select).
    How do i go about it. I'm using ADF-struts-UIX application on Jdeveloper 9.0.5.2
    Thanks.

    Jonas, I've downloaded the sample application from your ADF UIX Editable table tip but have some problems.
    I can't even open the emp.table.uix file - errors are:
    Parsing error. Unable to parse binding.
    javax.servlet.jst.el.ELException:Function ctrl:createSortableHeaderModel was not found.
    and
    javax.servlet.jst.el.ELException:Function ctrl:getSortOrder was not found.
    Also - is there a place in the sample where you define the sample tables? They do not seem to match the standard sample emp table, for instance.
    I've just started using JDeveloper and would like to use the solution.
    Thanks - Linda

  • Inserting multiple rows in child table

    i have two entity beans (main and child) with relationship one to many .... when i insert one row in main table (ie when i make one object for main entity bean)... how to insert multiple rows in child table...

    Can anyone pls provide some sample code for the above.. how to pass a collection and populate it in the child table.
    1.Where to pass the collection, to the childbean directly or to the parent bean and then itereate to the collectio and create child bean.
    Much obliged if you could paste some code for the above..

  • Inserting multiples rows into a table using function or procedure..

    How do i insert multiples rows into a table using function or procedure?
    Please provide me query..

    Use FORALL bulk insert statement...
    eg:
    procedure generate_test_data as
    type cl_itab is table of integer index by pls_integer;
    v_cl_itab cl_itab;
    type cl_vtab is table of varchar2(25) index by pls_integer;
    v_cl_vtab cl_vtab;
    type cl_dtab is table of date index by pls_integer;
    v_cl_dtab cl_dtab;
    begin
    for i in 1.. 100 loop
              v_cl_itab(i):= dbms_random.value(1,1000);
              v_cl_vtab (i):=dbms_random.string('a',20);
              v_cl_dtab (i):=to_date(trunc(dbms_random.value(2453737, 2454101)),'j');          
         end loop;
         forall i in v_cl_itab.first .. v_cl_itab.last
              execute immediate 'insert into test_order values( :n, :str , :dt ) ' using v_cl_itab(i), v_cl_vtab (i), v_cl_dtab (i);          
         commit;
    end;

  • Insert multiple rows in a table

    Hello Apex expert,
    I need help on insert multiple rows. it may look easy but I don't know how to do it.
    I have a table (with name found_table) which has these fields: found_ item_id, item_name, current_location, cost_center, tag_number. Also, I have a table (with the name transition) which has these fields: transition_id, found_item_id (FK to found_table), from_location, to_location, From_cost_center, to_cost_center, tag_number.
    I have an interactive report on found_table which I would like to add checkbox to all rows of the report. When the user checks any rows and press submit, I would like to send all these selected rows to another page which I have a form on transition table. The user will select a to_location and to_cost_center from this page (by the way from_location and from_cost_center and tag_number is the same as current_location and cost_center, tag_nuber from found_table, which I figured it out how to show those as a default in the new form). Now I want when a user selects the new location and cost center and press submit, all those selected rows be inserted in transition table with new locations.
    I read several threads on forum, but I could not find a solution for my problem. I will appreciate your help.
    Thanks,
    Atousa

    Hello again,
    I created a report with check box. I also added two selected list at the top of the region to select the location and cost center. Also, there is a transfer button(as submit) to insert the new data to table. Now I need the insert process. I tried different insert process but none of them is working for me:(((
    I created an example of what I need to do in the apex that you can take a look and give me some advise. The link is:
    What I need to do is:
    When a user selects several rows by using checkbox and selects To_LOCATION, and TO_COST_CENTER from selected list, and clicks on transfer, all the data should be insert in to another table with the name transition as follows:
    from found table to transition table
    found_item_id(pk) found_item_id (fk)
    current_location from_location
    cost_center from_cost_center
    tag_number tag_number
    selected list (to_location) to_location
    selected list (to_cost_center) to_cost_center
    Please help me on that. I appreciated.
    Atousa
    Edited by: Atousa.M on Jul 21, 2011 10:55 AM

  • Inserting multiple rows into a table using a multiple-select list

    I'm trying to figure out how to take the output of a multiple-select list (":" separated list of values) and use that to update a table by inserting multiple rows based on the values. Is there a straight-forward way to do that in APEX?
    Thanks.
    Chris

    Hi Chris,
    I think this should give you what you need: Working with a Multiple Select List Item
    --Jennifer                                                                                                                                                                                                                                                                                                                                                                                                   

  • Inserting multiple rows into a table (using sequences)

    Hi!
    I want to insert multiple rows into a db table, but I don't know how.
    I know how to insert 1 row using a sequence:
    I put all the fields in the jsp form's page and in the submit page I put something like this:
    <jbo:Row id="myRow" datasource="ds" action="Update" rowkeyparam="MyRowKey" >
    <jbo:SetAttribute dataitem="*" />
    </jbo:Row>
    But how can I insert multiple rows like this:
    Id          Name
    1          ana
    2          monteiro
    3          maria
    Thanks!

    Hi Chris,
    I think this should give you what you need: Working with a Multiple Select List Item
    --Jennifer                                                                                                                                                                                                                                                                                                                                                                                                   

  • Inserting Multiple Rows into a Table

    I am having problems insert multiple rows. I am using Table1.Row1.instanceManger.addInstance(1).
    I try adding another line using
    Table1.Row2.Cell2.value.#text= "TEST"
    and I get an error acessor is unknown. I assume this is an index issue. Can someone tell me if I am doing this wrong and discuss table indexes?

    The first thing I notice is that your variable, "num," isn't initialized in the FOR loop like I'm used to seeing.. The next thing I would try would be declaring my variables outside of the loop. Something like this maybe.
    String query = null;
    Statement stmt = null;
    int rowsUpdated = 0;
    for (int num = 0; num < 10; num++);     {
         query = "INSERT into apartment (apartmentID,blockID) VALUES ('"+num+"','"+aid+"')";
         stmt = con.createStatement();
         rowsUpdated += stmt.executeUpdate(query);
    }Let me know how it goes.
    -Aaron
    http://www.WeKnowErrors.com/ A free Wiki for error codes and computer problems.

  • Inserting Multiple Rows into Database Table using JDBC Adapter - Efficiency

    I need to insert multiple rows into a database table using the JDBC adapter (receiver).
    I understand the traditional way of repeating the statement multiple times, each having its <access> element. However, I am just wondering whether this might be performance-inefficient, as it might insert records one by one.
    Is there a way to ensure that the records are inserted into the table as a block, rather than record-by-record?

    Hi Bhavesh/Kanwaljit,
    If we have multiple ACCESS tags then what happens is that the connection to the database is made only once. But the data is inserted row by row.
    Why i am saying this?
    If we add the following in JDBC Adapter..logSQLStatement = true. Then incase of multiple inserts we can see that there are multiple
    <i>Insert into tablename(EMP_NAME,EMP_ID) VALUES('J','1000')
    Insert into tablename(EMP_NAME,EMP_ID) VALUES('J','2000')</i>
    Doesnt this mean that rows are inserted one by one?
    Correct me if i am wrong.
    This does not mean that the transaction is not guaranted. Either all the rows will be inserted or rolled back.
    Regards,
    Sumit

  • Insert Multiple rows into the table from that table data

    Hi All,
    I have a requirement like to insert mulitple rows into the table from that table data only(I need to replicate the data).
    In this table primary key is composite primary key with all foreign keys.primary key also including the Date foreign key.I need to change that date at the of insertion.
    INSERT
    INTO myschema.Fact_page_performance
    time_sk ,
    batch_id ,
    delta_msec ,
    delta_user_msec,
    error_code_sk ,
    content_errs ,
    element_count ,
    page_bytes ,
    Available ,
    date_sk
    VALUES
    (SELECT time_sk ,
    batch_id ,
    delta_msec ,
    delta_user_msec,
    error_code_sk ,
    content_errs ,
    element_count ,
    page_bytes ,
    Available
    FROM myschema.FACT_PAGE_PERFORMANCE_BACKUP
    WHERE date_sk=20090509,20090510
    But it is giving the error like missing Expression.
    Could anyone please help to me.
    Thanks and Regards
    Swetha.

    You can have either VALUES or SELECT not both
    INSERT
    INTO myschema.Fact_page_performance
    time_sk ,
    batch_id ,
    delta_msec ,
    delta_user_msec,
    error_code_sk ,
    content_errs ,
    element_count ,
    page_bytes ,
    Available ,
    date_sk
    SELECT time_sk ,
    batch_id ,
    delta_msec ,
    delta_user_msec,
    error_code_sk ,
    content_errs ,
    element_count ,
    page_bytes ,
    Available
    FROM myschema.FACT_PAGE_PERFORMANCE_BACKUP
    WHERE date_sk=20090509,20090510;

  • How to insert multiple rows in same table at once

    hi ,
    How can I insert more than one row in the same database table on single submit button.
    (i am using the ADF , EJB and Toplink for this example.)
    EMPLOYEEand DEPARTMENT tables will hold a common coloum deptno
    The method I have tried is as follows.
    I have created the UI that holds EMPLOYEE(DETAIL) details and a DEPARTMENT(MASTER) table and I have created two separate bean classes which hold the getters and setters for the corresponding tables.
    I have created a method in Department bean which will be called when we add the employee details
    public String addEmpdetails() {
    this.employeedetailslist.add(empdetails);
    return null;
    where employeedetailslist is a Arraylist and I want to pass the reference of employeebean in the array list.
    But this method will fail as I need to create the new employee bean object every time when ever I need to pass.
    How can I store values of multiple rows in bean.
    In the EJB session bean how can I commit multiple EMPLOYEE rows and DEPARTMENT values at once.

    The use of &variable in a script is actually syntax for a "substitution variable" in the SQL*Plus tool (other tools may also do the same), not an inherent part of SQL or PL/SQL itself.
    Whenever SQL*Plus is given a script it parses through it and if it encounters one of these it prompts for a value. This value is then substituted into the script before the script actually get's sent to the SQL or PL/SQL engine (process) on the database server. Once the script has gone to the database server it executes there and the results are passed back for SQL*Plus to display. However, the SQL and PL/SQL processes on the database server have no way to interface to the client machine, so they themselves cannot prompt for input from the client and you can't expect to prompt inside a loop as you are doing.
    What you need is a user interface on the client that can prompt repeatedly for values and then re-send the script, or call a procedure on the database each time. This can be done using shell scripts or dos batch files (depending on your client being unix/dos based) or using a front end application tool such as Java, .NET, Powerbuilder, PHP, Application Express (APEX) etc.

  • Inserting multiple rows in a table automatically

    Hello everyone,
    A question about SQL/PLSQL.
    I have a homework to create a table in SQL and to insert 10,000 rows in the table regardless of what the values are. The question is: is there a way (like a PLSQL code that has a loop) to inserts values in a table automatically without the need to insert the values 10,000 times manually?
    I really appreciate it and thanks in advance...

    Frank Kulash wrote:
    Is it possible to give me an example of a complete Connect BY/Insert statement would look like in my case?See the SQL Language reference manual
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_9014.htm#i2145081
    or your textbook for examples of inserting values with a subquery.
    A subquery using dual will work as well as a subquery using any other table; there's nothing about dual or CONNECT BY that complicates using a subquery in an INSERT statement.
    If you get stuck, post your best attempt here. If your problem involves an error, then post the complete error message, too.Frank,
    Thank you for your help and reply.
    I think I did not explain the situation well because what I am looking for is called <b>populating a table</b> and it seems that the CONNECT BY makes a loop of a single column and that is not the case.
    I have a table which is called customer and it contains 7 coulmns in which the first one (cust_id) is sequenced as shown below:
    create table customers
    cust_id int primary key,
    f_name varchar2(40),
    l_name varchar2(40),
    address varchar2(40),
    postnr varchar2(40),
    city varchar2(40),
    e_mail varchar2 (40)
    create sequence cust_id
    minvalue 0
    maxvalue 99999
    start with 1
    increment by 1
    cache 20;Now the quesiton is: how to populate this table with random data of 10,000 rows?
    Thank you very much in advanced.

  • Inserting multiple rows in internal table in debugging

    Hi All,
    I need to insert multiple records from an excel sheet to an intenal table while debugging. I can see there is an option for "append row" in debugging but not for multiple rows. Can anybody help in this regard.
    Thanks,
    Ravi.

    Hi,
    I am using new debugger for ECC 6.0..but could not find that option..Can you please indicate where exactly this option lies in the debugger.

  • Inserting multiple rows into database table

    hi
    I have a simple jsp/html page like this:
    <h1>Enter Comments</h1>
       <select name = "g1">
            <option>10</option>
            <option>20</option>
            <option>30</option>
            <option>40</option>
            <option>50</option>
            <option>60</option>
            <option>70</option>
            <option>80</option>
            <option>90</option>
            <option>100</option>
        </select> <input name = "comment1" type = "text" size = "60"><p>
         <select name = "g1">
            <option>10</option>
            <option>20</option>
            <option>30</option>
            <option>40</option>
            <option>50</option>
            <option>60</option>
            <option>70</option>
            <option>80</option>
            <option>90</option>
            <option>100</option>
        </select> <input name = "comment1" type = "text" size = "60"><p>but when i say : String fruit=request.getParameter("g1");
    String fruit=request.getParameter("comment1");
    only one gets written into the table. How would I write them both into seperate rows of the table? e.g.
    g1 comment1
    g1 comment1
    thank you all,

    change the name of the second select and second text element.
    You're only getting one because they're named the same, so the second one is overwriting the values of the first.
    HTH.

  • Inserting multiples rows into a table

    We have a job schedule table and a job date table.
    Job Schedule
    Job_ID Frequency
    1 1234567
    2 12-456-
    Job Date
    Job_ID Date
    1 01-JAN-07
    1 02-JAN-07
    We need to insert all DATES (not number of day in the week) into the Job Date table for a job according to the frequency. For example, for Job_ID 1 daily and for Job_ID 2 only Mondays, Tuesdays, Thursdays, Fridays, and Saturdays of the year.
    How can we achieve this?

    This question smells like this one...
    Inserting rows

Maybe you are looking for