INSERT ALL - Multiple table insert issue

There are three tables A, B, C. A has three rows. It has record of table B + 1 row. B has two rows, has record of table C + 1 row. C has one row.
SQL> SELECT * FROM A;
        C1         C2                                                          
         1          1                                                          
         2          2                                                          
         3          3                                                          
SQL> SELECT * FROM B;
        C1         C2                                                          
         1          1                                                          
         2          2                                                          
SQL> SELECT * FROM C;
        C1         C2                                                          
         1          1                                                          
I need to write a single query which make rows equal in all tables. I use INSERT ALL WHEN INTO method but get following errors:
SQL> INSERT ALL
  2  WHEN A.c1 NOT IN ( SELECT c1 FROM B) THEN
  3  INTO B VALUES(A.c1, A.c2)
  4  WHEN A.c1 NOT IN (SELECT c1 FROM C)  THEN
  5  INTO C VALUES(A.c1, A.c2)
  6  SELECT c1, c2 FROM A;
INTO C VALUES(A.c1, A.c2)
ERROR at line 5:
ORA-00904: "A"."C2": invalid identifier
However when I change columns names of all table and change INSERT ALL clause. I was able to execute it:
SQL> select * from a;
        A1         A2                                                          
         1          1                                                          
         2          2                                                          
         3          3                                                          
SQL> select * from b;
        B1         B2                                                          
         1          1                                                          
         2          2                                                          
SQL> select * from c;
        C1         C2                                                          
         1          1                                                          
SQL> INSERT ALL
  2  WHEN A1 NOT IN ( SELECT B1 FROM B) THEN
  3  INTO B VALUES(A1, A2)
  4  WHEN A1 NOT IN (SELECT C1 FROM C)  THEN
  5  INTO C VALUES(A1, A2)
  6  SELECT A1, A2 FROM A;
3 rows created.
My question is: What is the error with previous syntax? Is there any limitation of INSERT ALL statement.

Thanks guys  for prompt response.
I remove tablename aliase and it worked.
SQL>  INSERT ALL
  2    WHEN c1 NOT IN ( SELECT c1 FROM B) THEN
  3    INTO B VALUES(c1, c2)
  4    WHEN c1 NOT IN (SELECT c1 FROM C)  THEN
  5    INTO C VALUES(c1, c2)
  6    SELECT c1, c2 FROM A;
3 rows created.
SQL> select * from c;
        C1         C2
         1          1
         2          2
         3          3
SQL> select * from b;
        C1         C2
         1          1
         2          2
         3          3
SQL> select * from a;
        C1         C2
         1          1
         2          2
         3          3
SQL>
I really thought it will give me ambiguity error in insert, as column names are same in other table. Generally it gives.
Nice to know this thing of Multiple Insert

Similar Messages

  • Xsql multiple table insert

    I'm having trouble getting my xml document inserted into multiple tables. My xml has a parent child relationship. The main node is the parent I'll call <CAKE> then later on in the xml doc it has a node called <INGREDIENTS> which is a repeating element (more than 1). I need to insert information from the root node, <CAKE> into 1 table and all the info from <INGREDIENTS> node into another table.
    I've tried to get Steve Muench's book a try (chapter 14) but when I try to run the examples from the book (XMLLoader) i get the following error.
    C:\jdev9i\jdk1.3\bin\javaw.exe -ojvm -classpath C:\jdev9i\jdev\mywork\orxmlapp\Examples\ch14\classes;C:\oracle\ora81\RDBMS\jlib\xsu12.jar;C:\jdev9i\lib\xmlparserv2.jar;C:\jdev9i\jdev\lib\jdev-rt.jar;C:\jdev9i\jdbc\lib\classes12.jar;C:\jdev9i\jdbc\lib\nls_charset12.jar;C:\jdev9i\jlib\jdev-cm.jar;C:\jdev9i\rdbms\jlib\xsu12.jar;C:\jdev9i\lib\xmlparserv2.jar;C:\jdev9i\lib\xmlcomp.jar;C:\jdev9i\lib\oraclexsql.jar;C:\jdev9i\rdbms\jlib\xsu12.jar;C:\jdev9i\lib\xsqlserializers.jar;C:\jdev9i\lib\xmlparserv2.jar;C:\jdev9i\jdev\mywork\orxmlapp\Examples\ch14\classes;C:\jdev9i\jdev\mywork\orxmlapp\Examples\ch14\classes;C:\jdev9i\jdev\mywork\orxmlapp\Examples\ch14\classes -
    mx50m
    XMLLoader -file deptempdepend.xml -transform deptempdepend.xsl
    Processed 1 Documents
    Node doesn't belong to the current document.
    Error: java.lang.NullPointerException
    Process exited with exit code 0.

    I made the changes in the java files as per the previous
    reference, but I'm still getting an error. Seeing that I'm not
    much of a Java guy yet, I'm not sure where to debug the error.
    So here it is:
    XMLLoader -file deptempdepend.xml -transform deptempdepend.xsl
    Processed 1 Documents
    null
    Error: java.lang.NullPointerException
    Process exited with exit code 0.
    I tried to debug it and came to the conclusion that it is
    failing at line 22 of ConnectionFactory
    The value connNode is returend as null.
    I don't understand why:
    I ran testxpath.exe for the connections file.
    C:\jdev9i\jdev\mywork\orxmlapp\Examples\ch14>testxpath connections.xml
    Type an XPath expression to test and press [Enter]
    To quit, press [Enter] without entering a path.
    connections.xml> /connections/connection[@name='doug']
    <connection name="doug">
    <username>user</username>
    <password>password</password>
    <dburl>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=
    (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))
    (CONNECT_DATA=(SERVICE_NAME=dtxml.hmms)))</dburl>
    <driver>oracle.jdbc.driver.OracleDriver</driver>
    </connection>
    connections.xml>
    and it returned what i thought would be the correct nodes.
    Any help would be appreciated
    Doug

  • Insert into multiple table view

    I have a view with multiple table query and and INSTEAD OF trigger on the view that inserts into multiple tables. When I attempt to do a commit out of a ADF Creation Form, I get the following error: ORA-01779: cannot modify a column which maps to a non key-preserved table ORA-06512: at line 1.
    Has anyone had success inserting into multiple tables via a view that has more than one table?
    Thanks,
    Lisa

    Lisa,
    Sounds like your instead-of trigger may not be being called and you are trying to insert directly into the view.
    I did write a [url http://stegemanoracle.wordpress.com/2006/03/15/using-updatable-views-with-adf/]blog entry about using a view with instead-of triggers last year.
    John

  • Insert to multiple tables while keeping the referential integrity

    I would like to confirm whether we can have both updatable and reference for secondary entity. It seems to me that even though both updatable and reference can be checked for secondary entity, the secondary entity is not updatable.
    There are some scenarios that I hope to create the "parent" and "child" at the same time in the UI. For example, Employee and ProductExpertise which is in m:m relationship. We have three tables: Employee, EmployeeProduct, and Product. We have two view object, EmployeeVO which contains EmployeeEO, EmployeeProductVO which contains EmployeeProductEO and ProductEO. This can display EmployeeVO as master, and EmployeeProductVO as detail. However when we add a new product for the employee, we can only associate an existing product. We would like to create a new product and associate the product with employee. This cannot be achieved by the current EmployeeProductVO.
    I wonder if ADF supports inserting to multiple tables while keeping the foreign key reference integrity? In other words, in a 1:1..* (1 to 1 or 1 to many) relationship, must we have a master-detail view where we add parent first, then add child? Does ADF support adding both parent and child together with the correct foreign key assigned automatically for the child? Do we need to write code to do it?
    Any insight is appreciated.

    Hi,
    Assuming you are talking about ADF Business Components, yes, the framework can handle a batch insert that inserts both parent and child records in the same transaction. A few things that you may want to review:
    1). If you are using a database sequence for your primary keys (your question "Does ADF support adding both parent and child together with the correct foreign key assigned automatically for the child" made me think perhaps you were), have a read of the Fusion Developer's guide about the DBSequence type.
    2). In the same guide, have a read of section 38.8 - it talks about the small bit of code you may need to write to ensure the parent record is posted before the children, and also discusses about associations that are based on DB Sequences.
    Best,
    John

  • BizTalk 2013 R2 - Oracle client (Insert into Multiple tables) CompositE Transaction

    I know there is Composite Transaction of  inserting into multiple tables in SQL.
    Is there a way where we can have inserts into multiple table at once ? If yes, can anyone please provide step by step procedure to achieve this  
    MBH

    Here is a link on using Oracle DB w/ composite operations: 
    Performing Composite Operations on Oracle Database by Using BizTalk Server
    Rachit
    Please mark as answer or vote as helpful if my reply does

  • Inserting into multiple tables on one form using UIX

    We are developing an application using struts and UIX. We would like to be able to insert into three tables on one form(view). How can we accomplish this?

    This is more of an ADF question, you'll need to set up view object, than just drag it from the data control palette like normal.
    If it's not already set up as a view in the db (split into multiple tables), you'll need to create a view object that includes all the fields you want, based on multiple entity objects.

  • Multiple table insert via dblink

    Hi,
    We have an oracle database which contains a number of tables.
    From these tables I need to be able to populate a number of holding tables in a MSSQL database via a nightly scheduled job.
    Therefore I will insert into these tables via a procedure from my oracle tables.
    I need to ensure that if any of the inserts fail for a particular record I am uploading out of the five insert statements then the whole process is rolled back.
    I therefore having something like the following
    FOR cursor1_rec IN cursor1_cur LOOP -- This gives me the records I need to insert into the holding table for
    BEGIN
    INSERT into ms_holding_table_1
    (field1, field2)
    select 1,2 from oracle_table_1
    where id = cursor1_rec.id;
    INSERT into ms_holding_table_2
    (field1, field2, field3, field4)
    select 1,2,3,4 from oracle_table_2
    where id = cursor1_rec.id;
    INSERT into ms_holding_table_3
    (field1)
    select 1 from oracle_table_3
    where id = cursor1_rec.id;
    INSERT into ms_holding_table_4
    (field1, field2)
    select 1,2 from oracle_table_4
    where id = cursor1_rec.id;
    END;
    END LOOP;
    I need to ensure that if the insert for that particular cursor record fails on the 2nd insert statement, the first insert also rollbacks. Likewise if it fails on the 4th insert, I need to ensure that all 4 inserts are rolled back.
    If you could provide me with any information as to how to achieve this.
    Would issuing a savepoint before the first insert statement and then in my exceptions rolling back to the savepoint before the end of the loop suffice?
    Thanks in advance,
    ca84

    This is anonymous block but you can extend it add more defensive mechanism and def you can make it small procedure or part of some package. Hope this helps
    DECLARE
    CURSOR cur
    IS
    SELECT statement
    FROM table_name;
    BEGIN
    INSERT INTO ms_holding_table_1
    field1, field2
    SELECT 1, 2
    FROM oracle_table_1
    WHERE id = cursor1_rec.id;
    INSERT INTO ms_holding_table_2
    field1, field2, field3, field4
    SELECT 1, 2, 3, 4
    FROM oracle_table_2
    WHERE id = cursor1_rec.id;
    INSERT INTO ms_holding_table_3 (field1)
    SELECT 1
    FROM oracle_table_3
    WHERE id = cursor1_rec.id;
    INSERT INTO ms_holding_table_4
    field1, field2
    SELECT 1, 2
    FROM oracle_table_4
    WHERE id = cursor1_rec.id;
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN
    ROLLBACK;
    DBMS_OUTPUT.put_line (SUBSTR (SQLERRM, 1, 200));
    RAISE;
    END;

  • Insert/update multiple tables from one form.

    I'm working on an app. that requires the user to fill out a form. The contents from the form is then used to either insert new records or update existing records in multiple tables. Is that possible? Can someone give a details example?

    You should create a form like you would create it having one table. Use row_id as primary key. The rest of the process are done by the triggers - those will take care of updating the right table depending which column was hit.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Multiple-table inserts

    Hi,
    As part of a project I am working on I need to insert records into 3 tables and have to write a stored procedure for that. An e.g to that affect is as follows:
    Say I have 3 tables NAMES (lname,fname), ADDRESS(addr1,addr2), PHONE(hphone). How do I write a single stored proedure that takes five arguments (lname,fname,addr1,addr2,hphone) and insert these into each of the tables mentioned above. I want to do these in the context of one transaction. I.e. if in the worse case scenario I loose connection to the database after inserting into NAMES, ADDRESS tables, I should rollback the transaction because as the hphone has not been inserted into the PHONE table.
    I would greatly appreciate any input on this issue.
    Thanks.

    Just a quick example :
    SQL> insert into mytable1 select * from all_objects where rownum<=10;
    10 rows created.
    SQL> insert into mytable2 select * from all_objects where rownum<=10;
    10 rows created.
    SQL> <--------------- here, from an other session, I kill the current one
    SQL> select count(*) from mytable1 ;
    select count(*) from mytable1
    ERROR at line 1:
    ORA-00028: your session has been killed
    SQL> conn sysadm/****@mydb
    Connected.
    SQL> select count(*) from mytable1 ;
      COUNT(*)
             0
    SQL> select count(*) from mytable2;
      COUNT(*)
             0
    SQL> As expected, no rows in neither of the tables, insert statement haven't been committed.
    Of course, you shouldn't explicitly commit yourself between the insert statement to keep the data consistency. That's say, I wouldn't understand why search insert in one time into three tables with different structure.
    There is solution to insert into multitable in one time, but not to avoid what you think, see exemple here.
    Nicolas.

  • Insert in Multiple Tables ReceiverJDBC in sequence

    Hello Experts,
    I have an interface in which i need to insert into 4 tables, i know that is possible using receiver JDBC with multiple statement but My requirement is that data should be inserted in sequence.
    Table1 then table2 then tab3 and tab4 as they have constraints.
    I know that it can be achieved by using Stored Procedure, or having a staging table and then some other SP inserting data in sequence after reading staging table.
    Is there any other way to achieve it ? (NO BPM). Any new functionality to achieve that in PI 7.11 ?
    Regards
    Inder

    Since you are going to insert data into 4 tables in a sequence one after another , I see three options.
    You already mentioned  2 options  1) Stored procedure and 2) creating 4 statement data structure (one for each table)
    The third option is writing a SQL with join for the 4 tables and use action command = SQL_DML.   Example as follows....
    Write SQL code and place it in access tag.  Pass values for the columns using key tag...
    <stmt>
        <Customers action="SQL_DML">
          <access> UPDATE Customers SET CompanyName=u2019$NAME$u2019, Address=u2019$ADDRESS$' WHERE CustomerID='$KEYFIELD$u2019
          </access>
          <key>
            <NAME>name</NAME>
            <ADDRESS>address </ADDRESS>
            <KEYFIELD>100</KEYFIELD>
          </key>
        </Customers>
      </stmt>
    Refer this [link|http://help.sap.com/saphelp_nwpi71/helpdata/en/44/7b7855fde93673e10000000a114a6b/content.htm]...
    Hope this helps ....

  • Multiple table insert using receiver jdbc adapter

    Hi,
    I am trying to insert data in to two tables in a single structure using receiver jdbc adapter. I am not using any stored procedure to insert data instead directly inserting the data using PI. Please see the structure I am using.
    SOURCE side:
    DT_ABC_SENDER
    --IT_HEADER_TEXT
      -- EBELN
      -- LINENO
      --TDTEXT
    --IT_ITEM_TEXT
      -- EBELN
      -- LINENO
      --TDLINE
    TARGET side:
    DT_ABC_RECEIVER
    --InsertStatement
         --HEADER_TEXT
                -- action                         (insert)
                -- Table                          (Table 1)
                --access
                     -- IDS_ENQ_NO
                     -- IDS_DESC
                     -- IDS_TEXT
       --ITEM_TEXT
                -- action                         (insert)
                -- Table                          (Table 2)
                --access
                     -- IIS_ENQ_NO
                     -- IIS_DESC
                     -- IIS_TEXT
    Using the above structure I am able to successfully insert the data in Table 1 but data is not getting inserted in Table 2.
    In sxmb_moni it is saying message successfully delivered but I but there is data insertion took place in Table 2.
    Please help me urgently.
    Thanks in advance.
    Neeeraj

    Hi Neeraj,
    Add --InsertStatement statement for the second table structure in the same level of first InsertStatement.
    Target structure like this:
    DT_ABC_RECEIVER
    --InsertStatement
         --HEADER_TEXT
                -- action                         (insert)
                -- Table                          (Table 1)
                --access
                     -- IDS_ENQ_NO
                     -- IDS_DESC
                     -- IDS_TEXT
    --InsertStatement
       --ITEM_TEXT
                -- action                         (insert)
                -- Table                          (Table 2)
                --access
                     -- IIS_ENQ_NO
                     -- IIS_DESC
                     -- IIS_TEXT

  • Insert to multiple table using single DB Adapter

    Hi,
    I m using Jdev 11g Build JDEVADF_11.1.1.2.0_GENERIC_091029.2229.5536
    Can anyone tell me how can we do insert and update operations to mutliple tables using single DB adapter.
    I want to do insert in 2 tables and update the third using same DB apater. Is it possible?If yes, how?

    Hi,
    You can write a PL\SQL (Stored Procedure) to do your operations and call the PL\SQL code from DB Adapter.
    -Senaka

  • On insert into parent table insert into child tables

    hi all,
    please suggest me an idea for below scenario in plsql
    i have a main table where every day 10k records are inserted,
    now when ever the main table gets inserted the same records should inserted into two other child tables.
    main table will have 20 columns and two child tables will have 10 each columns with one common column in all three tables.
    suggest me if a trigger is best or a procedure is best for this if possible with a solution.
    thanks in advance

    look at INSERT ALL
    sample from http://psoug.org/reference/insert.html
    INSERT ALL
      INTO ap_cust VALUES (customer_id, program_id, delivered_date)
      INTO ap_orders VALUES (order_date, program_id)
      SELECT program_id, delivered_date, customer_id, order_date
        FROM airplanes;

  • Stored procedure to insert into multiple tables in sql server 2012, using id col from one table to insert into the other 2

    Hi all,
    Apologies if any of the following sounds at all silly but I am fairly new to this so here goes...
    I have 3 tables that require data insertion at the same time. The first table is the customers table, I then want to take the automatically generated custid from that table and inser it into 2 other tables along with some other data
    Here's what I have so far which does not work:
    CREATE PROCEDURE CustomerDetails.bnc_insNewRegistration @CustId int,
    @CompanyName varchar(100),
    @FirstName varchar(50),
    @LastName varchar(50),
    @Email nvarchar(254),
    @HouseStreet varchar(100),
    @Town smallint,
    @County tinyint,
    @Postcode char(8),
    @Password nvarchar(20)
    AS
    BEGIN
    begin tran
    insert into CustomerDetails.Customers
    (CompanyName, FirstName, LastName, EmailAddress)
    Values (@CompanyName, @FirstName, @LastName, @Email)
    set @CustId = (select CustId from inserted)
    insert into CustomerDetails.Address
    (CustomerId, HouseNoAndStreet, Town, County, PostCode)
    values (@CustId, @HouseStreet, @Town, @County, @Postcode)
    insert into CustomerDetails.MembershipDetails
    (CustomerId, UserName, Password)
    values (@CustId, @Email, @Password)
    commit tran
    END
    GO
    If anyone could help with this I would very much appreciate it as I am currently building an online store, if there's no registration there's no customers.
    So to whom ever is able to help, I thank you whole heartedly :)

    I hope by now it is apparent that statements like "doesn't work" are not particularly helpful. The prior posts have already identified your first problem.  But there are others.  First, you have declared @CustID as an argument for your
    procedure - but it is obvious that you do not expect a useful value to be supplied when the procedure is executed.  Perhaps it should be declared as an output argument so that the caller of the procedure can know the PK value of the newly inserted customer
    - otherwise, replace it with a local variable since it serves no purpose as an input argument.
    Next, you are storing email twice.  Duplication of data contradicts relational theory and will only cause future problems. 
    Next, I get the sense that your "customer" can be a person or a company.  You may find that using the same table for both is not the best approach.  I hope you have constraints to prevent a company from having a first and last name (and
    vice versa).
    Next, your error checking is inadequate.  We can only hope that you have the appropriate constraints to prevent duplicates.  You should expect failures to occur, from basic data errors (duplicates, null values, inconsistent values) to system issues
    (out of space).  I'll leave you with Erland's discussion for more detail:
    erland - error handling.
    Lastly, you should reconsider the datatypes you are using for the various bits of information.  Presumably town and county are foreign keys to related tables, which is why they are numeric.  Be careful you don't paint yourself into a corner with
    such small datatypes.  One can also debate the wisdom of using a separate tables for Town and County (and perhaps the decision to limit yourself to a particular geographic area with a particular civic hierarchy). Password seems a little short to me. 
    And if you are going to use nvarchar for some strings, you might as well use it for everything - especially names.  Also, everyone should be security conscious by now - passwords should be encrypted at the very least.
    And one last comment - you really should allow 2 address lines. Yes, two separate ones and not just one much larger one.

  • Insert into multiple tables using a page variable

    Hi Guys,
    I was going to trawl the PL/SQL forum for this but as I need to use a page variable I thought I would try here first.
    I have 4 tables 2 live and 2 archive, company_table, company_table_arch, product, product_arch the tables are set up with a company Id as the join.
    you can have multiple products to a company.
    what I want to do is have an archive button on a form that will select the current record on the company table, and insert it into archive then select all records with that id in the product table and insert them into the product_arch table.
    I was thinking about doing this as a couple of page proccess, sound about right?
    the other option was using a package,
    is it possible to use page variables in a package? If so what is the sintax
    cheers
    Bjorn

    OK, I have got the basis of this working I press the archive button and the records update as per the code.
    I have one problem however.
    The button is on a form. and if the user updates the form then presses the archive button it copies the data before the table is updated (the table is updated using a save button).
    One way round this would be to jump to an "are you sure?" page
    Does anyone know a better way of doing this?
    cheers
    Bjorn

Maybe you are looking for

  • MC46 & MC50

    Hi All, Can anyone throw light on these two standard reports 1) MC46 - Slow Moving Items 2) MC50 - Dead Stocks Do these two transactions consider 601 Movement Type or any Ales relevant movements. Thanks & Regards, Vinod

  • Oc4j restart problem.

    Hi , By using controller i am running my script ,the script is taking to OHS and OHS is routing the request to OC4J .It was working fine for the first time .i need to stop the oc4j and again bring back the oc4j server,this time OHS is routing the req

  • New Camera RAW to DNG but DNG not recognised

    I recently purchased a Sony Cybershot RX100M3. The RAW files are Sony's ARW2. I have Photoshop CS4 and Bridge. Naturally they won't recognise the new RAW files. I converted then to DNG using Adobe DNG converter. However CS4 and Bridge would not recog

  • Hi, I wanted to up upgrade my iPhone 4 from ios 4.1 to ios 5.1.1 and now i'm stuck in recovery mode and the restore doesn't work

    Hi, I wanted to up upgrade my iPhone 4 from ios 4.1 to ios 5.1.1 and now i'm stuck in recovery mode and the restore doesn't work I tried to restore with ios 5.1.1, with ios 5.0.1 and with ios 4.1 none is working

  • HT4236 Windows has stopped this device because it has reported problems. (Code 43)

    Cpu does not recognize the IPod Nano Gen6 since upgrading to new device and getting this error code...Windows has stopped this device because it has reported problems. (Code 43).  I have even uninstalled and reinstalled ITunes...still no joy.  Sugges