May returning Clause be used w/ INSERT INTO...SELECT FROM

Hi,
I use Oracle 8i: 8.1.7.2.0.
I'd like to insert multiple rows into a table, and get back certain inserted columns into a collection variable. Is this possible?
Eg:
INSERT INTO foo
f1
, f2
SELECT b1, b2...
FROM bar
RETURNING f1 bulk collect into collection
This compiles, but yields a "command not properly ended" error at runtime--I assume because the "returning" binds to the SELECT subquery, and not to the main INSERT query.
Is there a way to do this?
By the way, I already know this works when INSERTing just 1 row via the "values" clause.
Regards,
--IG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Hi,
Try this way:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL>
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
  2     TYPE emp_t IS TABLE OF VARCHAR2(30);
  3     emp_list emp_t;
  4 
  5     TYPE emp_t2 IS TABLE OF NUMBER;
  6     emp_code emp_t2;
  7  BEGIN
  8 
  9     emp_list := emp_t('John',
10                       'Doe',
11                       'Max');
12 
13     FORALL i IN emp_list.FIRST .. emp_list.LAST
14        INSERT INTO emp
15           (id,
16            NAME)
17        VALUES
18           (employees_seq.NEXTVAL,
19            emp_list(i))
20        RETURNING id BULK COLLECT INTO emp_code;
21 
22     FOR i IN emp_code.FIRST .. emp_code.LAST LOOP
23        dbms_output.put_line(emp_code(i));
24     END LOOP;
25  END;
26  /
213
214
215
PL/SQL procedure successfully completed
SQL> commit;
Commit complete
SQL> select * from emp;
        ID NAME
       213 John
       214 Doe
       215 Max
SQL>Regards,
Edited by: Walter Fernández on May 8, 2009 12:59 PM -- Adding query on emp table...

Similar Messages

  • Commit for every 1000 records in  Insert into select statment

    Hi I've the following INSERT into SELECT statement .
    The SELECT statement (which has joins ) has around 6 crores fo data . I need to insert that data into another table.
    Please suggest me the best way to do that .
    I'm using the INSERT into SELECT statement , but i want to use commit statement for every 1000 records .
    How can i achieve this ..
    insert into emp_dept_master
    select e.ename ,d.dname ,e.empno ,e.empno ,e.sal
       from emp e , dept d
      where e.deptno = d.deptno       ------ how to use commit for every 1000 records .Thanks

    Smile wrote:
    Hi I've the following INSERT into SELECT statement .
    The SELECT statement (which has joins ) has around 6 crores fo data . I need to insert that data into another table.Does the another table already have records or its empty?
    If its empty then you can drop it and create it as
    create your_another_table
    as
    <your select statement that return 60000000 records>
    Please suggest me the best way to do that .
    I'm using the INSERT into SELECT statement , but i want to use commit statement for every 1000 records .That is not the best way. Frequent commit may lead to ORA-1555 error
    [url http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:275215756923]A nice artical from ASKTOM on this one
    How can i achieve this ..
    insert into emp_dept_master
    select e.ename ,d.dname ,e.empno ,e.empno ,e.sal
    from emp e , dept d
    where e.deptno = d.deptno       ------ how to use commit for every 1000 records .
    It depends on the reason behind you wanting to split your transaction into small chunks. Most of the time there is no good reason for that.
    If you are tying to imporve performance by doing so then you are wrong it will only degrade the performance.
    To improve the performance you can use APPEND hint in insert, you can try PARALLEL DML and If you are in 11g and above you can use [url http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_parallel_ex.htm#CHDIJACH]DBMS_PARALLEL_EXECUTE to break your insert into chunks and run it in parallel.
    So if you can tell the actual objective we could offer some help.

  • Mechanism of a insert into select

    Hi
    I am using a insert with select in a batch program which is supposed to run just a little before midnight.
    My question is, when a insert into a table occurs, does oracle select all the rows before the insert starts, OR, does the insert occur simultaneously with the select.
    eg. table B has 4 rows
    data is being inserted into A from B
    does oracle select row1 from B and insert row1 into table A and then move to row2 in B and insert row2 into A
    OR
    does oracle select rows1 thro 4 in B before the first insert into A starts?
    If anybody could point me to a document/reference about that would be aweosme.
    --vj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    There is no need to know this kind of internals. A statement is atomic, so it either completes in total or not at all. Other sessions cannot see intermediate results, even your own session is not able to. If you would try, for example by using database triggers, you'll get a mutating table error to prevent that.
    Regards,
    Rob.

  • Urgent : Performance Issue DELETE , INSERT INTO SELECT, UPDATE

    Hi,
    NEED ASSISTANCE TO OPTIMIZE THE INSERT STATEMENT (insert into select):
    =================================================
    We have a report.
    As per current design following steps are used to populate the custom table whcih is used for reporting purpose:
    1) DELETE all the recods from the custom table XXX_TEMP_REP.
    2) INSERT records in custom table XXX_TEMP_REP (Assume all the records related to type A)
    using
    INSERT..... INTO..... SELECT.....
    statement.
    3) Update records in XXX_TEMP_REP
    using some custom logic for the records populated .
    4) INSERT records in custom table XXX_TEMP_REP (Records related to type B)
    using
    INSERT..... INTO..... SELECT.....
    statement.
    Stats gathered related to Insert statement are:
    Event Wait Information
    SID 460 is waiting on event : db file sequential read
    P1 Text : file#
    P1 Value : 20
    P2 Text : block#
    P2 Value : 435039
    P3 Text : blocks
    P3 Value : 1
    Session Statistics
    redo size : 293.84 M
    parse count (hard) : 34
    parse count (total) : 1217
    user commits : 3
    Transaction and Rollback Information
    Rollback Used : 35.1796875 M
    Rollback Records : 355886
    Rollback Segment Number : 12
    Rollback Segment Name : _SYSSMU12$
    Logical IOs : 1627182
    Physical IOs : 136409
    RBS Startng Extent ID : 14
    Transaction Start Time : 09/29/10 04:22:11
    Transaction_Status : ACTIVE
    Please suggest how this can be optimized.
    Regards,
    Narender

    Hello,
    Is there any relation with the Oracle Forms tool ?
    Francois

  • Inserting multiple selection from checkbox in to one column of the database

    Hi,
    how to insert multiple selection from checkbox into one column of the database.(I select array of values from checkbox ,then how to insert tat array of values iinto single column name).
    Anyone can u reply me
    Thanx

    hhhmmm.... is this what you mean?
    lets say you hava a checkbox1 with values value1, value2, value3 and you selected all there of them? then you want then to be stored in the database in one column?
    now the question is:
    Is it going to be one column one row?
    datafield
    value1,value2,value3
    Or one column multiple row?
    datafield
    value1
    value2
    value3
    Which is it?

  • How to use "insert into & select" in format search

    Hello,
    I am just wonderring whether you can help me solve this issue.
    I want to change the value of a field in the title area for a sales quotation. however, this field is not shown up on the interface.
    For example, there is a field in the title area, "OQUT.Ref1". You actually cannot see this field from the quotation interface or any other doc. Now I want to update the value of this field.
    What I am now trying to do is to create an field named "update" in the title area, use format search to update. the code for the command will be something like
    Insert into $[OQUT.Ref1.0]
    select $[OQUT.U_MFG#]
    here, U_MFG# is UDF. as you may understand, I want to copy the value in the U_MFG# to the field of "Ref1".
    However, when I run "Execute", it gives me error. I believe there is something wrong with the code of "Insert into $[OQUT.Ref1.0]
    Does anyone know how to write the code?
    many thanks
    Stanley

    Thanks both Suda and sagar. The reason I wanted to do this is because I wanted to have UDF info be shown on the  MS word-templated quotation document.
    As you know, when you click the word symbol, a word-templated doc will be generated. The client needs two completely different format of quotation printout. thus I plan to print one type from PLD and other type by clicking the Word symbol. but later, I found out that the UDF field cannot be selected on the MS word template, or only system fields.
    Thus, the only way I can do is to copy the value from udf to some unused sytem fields and then show that system fields on the MS word template.
    any idea do you have?
    I wanted to tell SAP that It is not useful if the udf fields cannot be inserted into word template.
    thanks
    Stanley

  • SSIS - Script Task creates a DTS var and using Foreach loop, Execute SQL needs to INSERT into table from this DTS var.

    I have a script task written in C# that creates an array of strings "arrayFields" after parsing a text file. It saves the array of strings in a DTS variable.
    Each row in array represents a row is comma separated and is a row that must be inserted into a table. For example,
    X and Z are fields in the table
    X1, X2,....Xn
    Z1,Z2,...Zn
    I am using a Foreach Loop  to grab each row and then  Execute SQL Task to take each row from the array and insert each field per row in a table,
    The SQL is something like,
    INSERT dbo.table values(field1, field2,...fieldn) arrayFields?
    What should this this INSERT look like?

    I guess you implemented
    Shredding a Recordset
    Based on what I understood (correct me if I am wrong) you have difficulties mapping the input parameters, if so here is the guide
    http://www.sqlis.com/sqlis/post/The-Execute-SQL-Task.aspx
    In short it might look like
    INSERT dbo.table  (ColumnA, ColumnB,...) VALUES (?,?...)
    The syntax for the T-SQL INSERT is http://technet.microsoft.com/en-us/library/dd776381%28v=sql.105%29.aspx
    Arthur
    MyBlog
    Twitter

  • Unable to insert into mysql from flash burrito

    I'm having issues inserting a record to mysql, if I use the test "test operation and use these values the it works fine, but now in the android app.
    values in my test operation
        id:0,
        type:"cool",
        navn:"vegar 16"
    the getall method works fine, and shows up on the network monitor, but the button dont work at all, nothing happends in the network monito, if I debug it I can see that the button works, any suggestions on what Im doing wrong?
    code in my view:
    <?xml version="1.0" encoding="utf-8"?>
    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:kunderservice="services.kunderservice.*"
            title="Home">
        <fx:Script>
            <![CDATA[
                import mx.events.FlexEvent;
                import valueObjects.Kunder;
                protected function list_creationCompleteHandler(event:FlexEvent):void
                    getAllKunderResult.token = kunderService.getAllKunder();
                protected function button_clickHandler(event:MouseEvent):void
                    var item:Kunder = new Kunder();
                    item.id=0
                    item.navn="vegar"
                    item.type ="test"
                    createKunderResult2.token = kunderService.createKunder(item);
            ]]>
        </fx:Script>
        <fx:Declarations>
            <s:CallResponder id="getAllKunderResult"/>
            <kunderservice:KunderService id="kunderService"/>
            <s:CallResponder id="createKunderResult2"/>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <s:List id="list" x="35" y="45" width="409" height="193"
                creationComplete="list_creationCompleteHandler(event)" labelField="navn">
            <s:AsyncListView list="{getAllKunderResult.lastResult}"/>
        </s:List>
        <s:Button id="button" x="20" y="406" label="Button" click="button_clickHandler(event)"/>
        </s:View>

    I really appreciate your help. Yes indeed, debugging and seeing what is going on in general is most difficult with flash!
    Once I get this cracked I should be able to complete a lot of what I am trying to achieve.
    After inserting some echo's into my php as such:
    <?php
    $player = $_POST['player'];
    $tournament = $_POST['tournament'];
    $position = $_POST['position'];
    $prize = $_POST['prize'];
    mysql_connect("localhost", "root","poker");
    echo "onnected to database"
    mysql_select_db("poker");
    echo "database connected";
    mysql_query("INSERT INTO results(player,tournament,position,prize) VALUES
    ('$player','$tournamnet','$position','$prize')");
    echo "result added";
    ?>
    The returned info is a load of nonsense to me:
    response from server:  %3C%3Fphp%0A%24player%20=%20%24%5FPOST%5B%27player%27%5D%3B%0A%24tournament%20%3D%20%24%5 FPOST%5B%27tournament%27%5D%3B%0A%24position%20%3D%20%24%5FPOST%5B%27position%27%5D%3B%0A% 24prize%20%3D%20%24%5FPOST%5B%27prize%27%5D%3B%0A%0Amysql%5Fconnect%28%22localhost%22%2C%2 0%22root%22%2C%22poker%22%29%3B%0Aecho%20%22onnected%20to%20database%22%0Amysql%5Fselect%5 Fdb%28%22poker%22%29%3B%0Aecho%20%22database%20connected%22%3B%0Amysql%5Fquery%28%22INSERT %20INTO%20results%28player%2Ctournament%2Cposition%2Cprize%29%20VALUES%20%0A%28%27%24playe r%27%2C%27%24tournamnet%27%2C%27%24position%27%2C%27%24prize%27%29%22%29%3B%0Aecho%20%22re sult%20added%22%3B%0A%3F%3E

  • How to insert into table from an Datatable ?

    Hi Friend,
    I have a datatable that is created at some point in my SSIS as an object.
    I need to insert the data into a sql table, how should I do that ?
    I have this:
            Dim oleDA As New OleDbDataAdapter
            Dim dt As New DataTable
            Dim col As DataColumn
            Dim row As DataRow
            Dim sMsg As String
            oleDA.Fill(dt, Dts.Variables("history").Value
    and want to insert into a table in a SQL DB
            Dim sqlCon As New SqlClient.SqlConnection("server=Myserver\SQL2008R2;database=MyDB;Integrated Security=SSPI")
            Dim sqlreader As SqlClient.SqlDataReader
            sqlCon.Open()
    Thanks in advance,
    Pat
    Patrick Alexander

    Convert it to a ADO .Net recordset and store it in a object variable in SSIS.
    Then you can use it to populate the table using foreach loop with ado enumerator
    http://www.codeproject.com/Articles/10503/Simplest-code-to-convert-an-ADO-NET-DataTable-to-a
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to insert into table from a xml with XDE for java?

    want to insert into the oracle tables from the xml with XDE for java, some sample better. thank you.

    XML Document may be stored in a SQL database with XML SQL Utility.
    http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10794/adx08xsu.htm#i1008168
    XML Document may be stored in a SQL database with Oracle XML DB.
    http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10790/xdb03usg.htm#CEGFECFH

  • Insert into MSSQL from Oracle

    Hello together,
    I'm a little bit frustrated. The follwoing is my problem:
    I want to insert some values from an Oracle 10gR2 database into a MSSQL database (SQL Server 2008 R2).
    Therefor I'm using DG4ODBC 11.2.0.3. The connection is working absolutly fine.
    I want to insert five values from five columns from oracle.table-a into a msssql table-b.
    But I'm hitting the error:
    Invalid character value for cast specification.
    Two columns from the oracle table are chars size 12 and 40, and three are number size 5.1, 5.1 and 4.
    The MSSQL column definitions are varchar40, varchar50, 2x float8 and int.
    The column assignments are:
    Oralce -> MSSQL
    a. char 12 -> varchar40
    b. char 40 -> varchar50
    c. number 5.1 -> float8
    d. number 5.1 -> float8
    e. number 4 -> int4
    The insert works greate for a,b and e but nor for c and d.
    I tried so many solutions (cast, to_binary_float, nls_character_format, nls_theritpory etc..) but nothing helps.
    I always hitting this error.
    Can anyone help me with this problem?
    cheers
    Joe

    Hi together,
    I fixed the problem. I multiply the origin number with 10. The result is a number without any comma. During the insert into MSSql I divide by 10.
    I now, this is a very strange solution but it works.
    Yes I know this helps only, because the column can only save number with one decimal place. For higher decimal places you have to multiple it with 100 or 1000 or......
    Hope this helps also other peoples.
    kind regards
    Joe

  • Inserting multiple selection from checkbox into one column of the database

    Hi,
    How to insert multiple selection values from checkbox into one column of the database.
    Anyone can u help me
    Thanx

    hi
    try to use request.getParameterValues("fieldname")

  • Procedure or function for insert into select ...

    Hi!
    We need to know if we can create a procedure or function that will run the following script:
    insert into agent.train_schedule
    select 4000, '06:25' ,trunc(sysdate, 'year')+t.n
    from agent.trains, (select rownum -1 n from dual
    connect by level <= 365) t
    where agent.trains.id = 4000 and
    agent.trains.weekday like '%'||to_char(trunc(sysdate, 'year')+t.n, 'd',
    'nls_date_language=AMERICAN')||'%';
    The script inserts the train schedule dates into the train schedule table in accordance to the trains table.
    Any help would be appreciated.
    Thanks!

    Try the below:
    Create Or Replace procedure test_proc(p_train_no number, p_train_time varchar2) as
    begin
    insert into agent.train_schedule
    select p_train_no, p_train_time ,trunc(sysdate, 'year')+t.n
    from agent.trains, (select rownum -1 n from dual
    connect by level <= 365) t
    where agent.trains.id = p_train_no and
    agent.trains.weekday like '%'||to_char(trunc(sysdate, 'year')+t.n, 'd',
    'nls_date_language=AMERICAN')||'%';
    end;
    Call the procedure from the gui also pass the train number and the train time.
    Regards,
    Samujjwal Basu

  • Can ResultSetMetaData() return the table name if it is selected from a view

    hi all
    can anyone tell me if ResultSetMetaData() can return the name of the table if it is selected from a view? thanks, i tried and it didn't return nothing. is it because the view is treated differently than table in ResultSetMetaData?

    hi all
    can anyone tell me if ResultSetMetaData() can return
    the name of the table if it is selected from a view?
    thanks, i tried and it didn't return nothing. is it
    because the view is treated differently than table in
    ResultSetMetaData?I would say "no". A view could be a multi-table join query, or maybe even a no-table query. The bigger picture I think though, is that you shouldn't need to know what the underlying table(s) were for this query - smells of a mis-design.

  • Problem inserting into DB from XML using XSQL

    Hi everyone!
    I try to load an XML document into a DB table, for the moment i only get access to a MySQL DB server, but i hope to use ORACLE soon. My problem is the next one:
    when i try to execute an insert query against the DB server it always fails, i get no problem doing another operation like select and so on. I have try in several ways:
    1. From a XSQL page using the tags xsql:insert-request, in the case the error looks like:
    Action xsql:insert-request
    Message org.gjt.mm.mysql.jdbc2.Connection
    2. I also have try the MoreoverIntoNews java examples, and the problem seem similar:
    Exception in thread "main" oracle.xml.sql.OracleXMLSQLException:
    org.gjt.mm.mysql.jdbc2.Connection
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:1967)
    at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1060)
    at MoreoverIntoNewsstory.main(MoreoverIntoNewsstory.java:43)
    How can i fix this problem?
    I also have realize that when i remove from the CLASSPATH the file "classes12.zip" then i
    get next exception:
    java.lang.NoClassDefFoundError: oracle/sql/CLOB
    Then it seems that the XML-SQL utilities (XSU) are only to work with Oracle and not with other DB engine.
    Thanks in advance.
    Marcos.

    Is there a solution to this problem? Does anyone have any suggestions?

Maybe you are looking for

  • Issues With Tablet Sensitivity

    I just recently purchased my touchscreen notebook and installed a digital art program (Krita) with no problem. I plugged in a wacom tablet that I've had for years and it seemed to have installed fine, it made a beeping noise to indicate it had been p

  • 3 Questions: Docking Panels, Find doesn't work

    Hello, I am relatively new to Prelude and I have three questions. -First for some reason I no longer can move the panels to other positions and lock them in. That little hot spot tab is missing ?? -Secondly, The finder in the project panels isn't fin

  • What is the best way to include external files in an application?

    I am developing a vocabulary-training program (Adobe AIR using Flex Builder 3). Asks you what an equivalent of a czech word is in english and the other way. I am storing the "dictionaries" in external XML files. I would like to include about twenty o

  • Get Profit Center Function Module

    is there any Get Profit Center Function Module.. what for is it used ? how way is it related to profit center. What are the transaction codes of MR1M,OKB9. What is the significance of using these ? Could any body please explain. THANKS IN ADVANCE...

  • Error 36 with time machine

    When importing Aperture Library from time machine, error 36 appears, and only part of the library copies to my computer. How can I get around this?