Insert a subquery

idont know ewhy this statment is not working and what is the right statement
insert into deleted_orders(employee,order_id,user_id)values('yy',(select order_id,user_id from orders where order_id=491))

insert into deleted_orders (employee,order_id,user_id)
select 'yy',order_id,user_id from orders where order_id=1

Similar Messages

  • How to insert with select in table with object types

    I am in the proces of redesigning some tables, as i have upgraded from
    personal oracle 7 to personal oracle 8i.
    I have constructed an object type Address_type, which is one of the columns
    in a table named DestTable.
    The object type is created as follows:
    CREATE OR REPLACE TYPE pub.address_type
    AS OBJECT
    Street1 varchar2(50),
    Street2 varchar2(50),
    ZipCode varchar2(10));
    The table is created as follows:
    CREATE TABLE pub.DestTable
    (id INTEGER PRIMARY KEY,
    LastName varchar2(30),
    FirstName varchar2(25),
    Address pub.address_type);
    Inserting a single row is ok as i use the following syntax:
    Insert into DestTable(1, '******* ', 'Lawrence', pub.address_type(
    '500 Oracle Parkway', 'Box 59510', '95045'));
    When i try to insert values into the table by selecting from another table i
    cannot do it and cannot figure out what is wrong
    I have used the following syntax:
    Insert into DestTable
    id, name, pub.address_type(Street1, Street2, ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    I have also tried the following syntax:
    Insert into DestTable
    id, name, pub.address_type(Address.Street1, Address.Street2,Address.ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    What is wrong here ?
    null

    Magnus,
    1. Check out the examples on 'insert with subquery' in http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a85397/state21b.htm#2065648
    2. Correct your syntax that repeated the column definition after "insert into ..."
    Insert into DestTable
    id, name, pub.address_type(Street1, Street2, ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    Regards,
    Geoff
    null

  • Set results of Report1 as filters/prompts for Query3

    Hi everybody.
    Unfortunately I tried to find a solution to my problem in this forum, but I couldn't find anything similar. Therefore I'd like to post the problem as a new thread.
    Here it is:
    I have a Query1, which leads to a Report1, that contains lets say 15 entries, in my case passenger cars. Each of those passenger cars has 5 different attributes, like manufactuerer code, mileage, age, listprice and damages. Mileage, age, listprice and damages are being rounded to 1000-Euros.
    I have another Query2, that contains a Report2 with sold vehicles, around 5.000 entries. All of those entries also have the same attributes, as seen in Report1.
    Now I'd like to create a Query3, that takes the results of Report1 as filters/prompts. Report3 should basiclally show Report1, but with additional averages of sales prices, may be even for different sales channels (cross-tab?!).
    I've editing rights to our WebIntelligence client, so I can create WebI queries. I have neither access to the BO universe, nor am I an administrator for this universe.
    Can anyone help? THX
    Sven

    The only way I can think of to achieve it is by using a subquery in Query3.
    Let's say this is your Query1:
    Objects:
    class1_dimension_car, class1_damages
    Filters:
        class1_my_date equal to 'Prompt insert a date'
    and
        class1_my_company equal to 'Prompt insert a company id'
    Then your Query3 should be like this:
    Objects:
    class2_dimension_car, class2_averages
    Filters:
        my_date equal to 'Prompt insert a date'
    and
        my_company equal to 'Prompt insert a company id'
    and
       class2_dimension_car  in (  --this is a subquery, it is inserted with subquery button)
                            (  class1_dimension_car
                                    class1_my_date equal to 'Prompt insert a date'
                                 and
                                    class1_my_company equal to 'Prompt insert a company id'
    Note that this subquery is almost equal to Query1

  • Ora-00933 with JDBC thin

    Hi,
    after changing the Oracle DB-driver from the one provided
    with CF Enterprise to Oracle JDBC thin I run into ora-00933
    "Command not properly ended" exceptions. The SQL code syntax ist
    correct (runs in SQL*plus) and worked fine before. It seems to be
    related mostly to insert from subquery...
    Has anybody an idea what is going wrong?
    Are there any patches / fixes available ? (working with CF8
    Fix2, Oracle 10gR2, W2k3)
    Thanks in advance

    quote:
    The SQL is something like
    Your SQL, as it stands, looks OK to me, except
    you have an unnecessary extra set of ( ) around your select
    statement.
    insert into fu_dokument_status (oid, benutzer, status, datum)
    select 123, 'asdf', 'gelesen', sysdate
    from dual
    where not exists (select *
    from fu_dokument_status
    where oid=123
    and benutzer='asdf'
    and status='gelesen' )
    Having said that, you obviously provided the SQL
    after parameter substitutions have been made, and it would
    have been much more useful to see the actual CF code that you are
    using, you know, what is actually contained in your CFQUERY. I
    suspect that there may be something else going on with the way that
    it is written. Generic "something like" isn't terribly helpful.
    Phil

  • Subquery for inserting doesn't work in Oracle package

    I have experienced a very strange scenario while inserting data inside a Oracle package.
    I have two tables:
    - table "A"
    Columns: "ID", "Value1", "...."
    - table "A_Backup", which contains backup data for table A. It has one more column "BATCH_NUMBER" than table A
    Columns: "BATCH_NUMBER", "ID", "Value1", "...."
    I created following procedure in a package to backup data from table "A" to "A_Backup".
    procedure proc_backup (v_id in number) is
    declare
    v_batch_number varchar2(20);
    begin
    /** generate a batch number using system date */
    select 'BATCH' || to_char(sysdate, 'YYYYMMDDHH24MISS') into v_batch_number from dual;
    /** insert Batch_NUMBER + data from A into A_BACKUP */
    insert into A_BACKUP (select v_batch_number, id, value1, ... from A where A.id = v_id);
    end proc_backup;
    When I debug the procedure, it will not insert any data into A_BACKUP. Apparently, there are some data in table "A" meets criteria "A.id = v_id".
    The strange thing: If I create same procedure. But this time I didn't put procedure inside the package, insert query will work.
    Please help, I have spent a couple of days on this and never make it work. I also tried cursor, it doesn't work either. It seems Oracle package doesn't support "virtual table" (subquery in insert) or whatever you call it.

    Welcome to the forum!
    Whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    I don't see any package or test code that calls the procedure or error messages or results from any procedure calls.
    You say you have a problem with a package but don't post the package version of the code you are having a problem with.
    How is anyone supposed to find a problem in code that you don't post? And when you post use \ tags as discussed in the FAQ.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Subquery inside INSERT INTO

    Hi !
    I have a problem to put a Subquery inside an INSERT INTO-Statement.
    I try it this way: (the select-statemnet alone is running fine) (the listing is shortened)
    INSERT INTO W_CACS_ENTRY
    location_code
    ,case_num
    ,billing_account_id
    select
    a.location_code
    ,a.case_num
    ,billing.billing_account_id
    from
    select
    max(billing_account_id) as billing_account_id
    from
    select /*+ parallel ( a 4)*/
    account_no
    ,external_id
    ) case,
    w_billing_accounts bill
    where
    case.account_no = bill.account_no
    ) billing
    w_CO_CASE_HIST a
    where .....bla...
    When I try to compile it i get the following error:
    ORA-Seperator S223:
    (S223) Expecting: statement_terminator BEGIN CASE DECLARE END IDENTIFIER IF LOOP
    Is it forbidden to use Subquerys inside an INSERT TO statement?
    Are there any other possibilities?
    thanks and greets
    bang

    yes, it's inside a PL/SQL-Package. I'm using TOAD to develop it.
    Here is the whole query:
    INSERT INTO W_CACS_ENTRY
        location_code
        ,case_num
        ,EVENT_TYPE
        ,EVENT_DATE
        ,event_id
        ,cacs_case_sequence
        ,part
        ,billing_account_id
    select
         a.location_code
        ,a.case_num
        ,'CACS IN' as EVENT_TYPE
        ,a.DATE_TIME as EVENT_DATE
        ,a.sequence_number as event_id
        ,seq_cacs_case_dwh.nextval as cacs_case_sequence
        ,substr(seq_cacs_case_dwh.currval, -1) as part  
        ,billing.billing_account_id   
        from
                select  /*+ use_hash (case bill) parallel (bill 4) */
                 case_num
                ,LOCATION_CODE
                ,max(billing_account_id) as billing_account_id
                from
                    select  /*+ parallel ( a 4)*/
                    account_no
                    ,external_id  as case_num
                    ,101010 as LOCATION_CODE
                    from
                    w_CUSTOMER_ID_ACCT_MAP ar
                    union all
                    select  /*+ parallel ( a 4)*/
                    account_no
                    ,external_id  as case_num
                    ,202020 as LOCATION_CODE
                    from
                    c_CUSTOMER_ID_ACCT_MAP ar 
                ) casec,
                w_billing_accounts  bill
                where
                casec.account_no = bill.account_no
                group by
                 case_num
                ,LOCATION_CODE
           ) billing
           w_CO_CASE_HIST a
            where a.coll_activity_code in ('EN','MS')
            and a.DATE_TIME > to_date ('01.01.2006','dd.mm.yyyy')
            and billing.case_num = a.case_num
            and billing.location_code = a.location_code
    ;

  • How to combine both values and subquery in the insert statement

    Hi everybody,
    This is a case of inserting rows into a final results table from a temporary one. Actually, one of the fields is not always given in the temporary table. Thus, when inserting the rows into the final results table, an error message comes up to.
    More clarification:
    final results table(F_RESULT): field1, field2, field3 ( they are also primary keys with not null constraint)
    temporary table(TEMP): field2, filed3
    Is it possible to combine both values and subquery branchs of the insert statement:
    Insert into F_RESULT (field2,field3) select field2,field3 from TEMP;
    Insert into F_RESULT (field1) values (0);
    into only one like this:
    Insert into F_RESULT (field1,field2,field3) values (0, select field2 form Temp, select field3 from Temp);
    Or there is another more effective solution. The main problem for me is the message that doesn't accept the null value. From the data integrity point of view, it is accepted to set field1 to zero.
    Any hints?
    Thanks for your reply.

    That's easy, you can select any value from a table:
    Insert into F_RESULT (field1,field2,field3)
    select 0, field2, field3 from Temp;

  • Override INSERT operation with subquery

    Hi, OTN.
    I have a form to update/insert a table.
    While INSERT one of the fields' value should be obtained by a subquery.
    SQL operation should look like this:
    INSERT INTO table1 (attribA, attribB, attribC)
    VALUES (valueA, valueB, ( SELECT max(valueC) + 1
    FROM table1
    WHERE table1.attribA = valueA
    It is necessary to complete insert in a single operation. Not possible to obtain a value with one query and insert it with another. Triggers also shouldn't be used.
    So i need to use a subquery. My JDev is 11.1.1.1.0.
    How is it done?
    Thanks

    I have problem with detailstamp not working on 11g.
    Let us consider : Item , SubItem relationship.
    Component : Item VO , SubItemVO , Item can have many subitem.
    1.Created ItemVO
    2.Create SubItemVO
    3.Create View Link based on ItemVo-ItemId that is FK in SubItem table.
    4.Created JSF page and Dragged ItemVO from Datacontrol to JSF Pagen as ADF ReadOnly Table.
    5.Expanded Item table structure in Structure window and open the detailstamp.
    6.Dragged SubItemVO in detailstamp as ADF ReadOnly table.
    Expected Result :
    1. ItemVO First Row
    1.SubItems belonging to ITEMVO First Row
    2.SubItems belonging to ITEMVO First Row
    2.ItemVO Second Row.
    1.SubItems belonging to ITEMVO Second Row
    Current Result :
    1. ItemVO First Row
    1.SubItems belonging to ITEMVO First Row
    2.SubItems belonging to ITEMVO First Row
    2.ItemVO Second Row.
    1.SubItems belonging to ITEMVO First Row
    2.SubItems belonging to ITEMVO First Row
    Description: Second ItemVO when expanded shows first ItemVO SUBITEMS.
    Thanks,

  • Subquery in insert into clause

    what is the use of using subquery in insert into clause.
    e.g. insert into (select empno from emp)
    values(1234)
    regards
    kiran

    Not really of common use, I think, but WITH CHECK OPTION option could be one reason for using that. Let's see an example :
    SQL> INSERT INTO
      2  (SELECT empno, ename, deptno FROM emp WHERE deptno < 20)
      3* VALUES (1111, 'Brown', 30)
    SQL> /
    1 row created.That's the same as
    SQL> insert into emp (empno, ename, deptno)
      2  values(1111, 'Brown', 30);But
    SQL> INSERT INTO
      2  (SELECT empno, ename, deptno FROM emp WHERE deptno < 20 WITH CHECK OPTION)
      3* VALUES (2222, 'Green', 30)
    SQL> /
    (SELECT empno, ename, deptno FROM emp WHERE deptno < 20
    ERROR at line 2:
    ORA-01402: view WITH CHECK OPTION where-clause violation
    SQL>Paul

  • Subquery in an INSERT

    I was reading in an Oracle book about the Subquery in an INSERT
    "INSERT INTO ( SELECT E.EMPLOYYE_ID,E.LAST_NAME,E.EMAIL,E.HIRE_DATE,E.JOB_ID,E.SALARY,E.DEPARTMENT_ID
    FROM EMPLOYEES E
    WHERE E.DEPARTMENT_ID = 50)
    VALUES(99999,'SOMA','FOLLA',SYSDATE,'PROG',60,60)"
    What is the purpose of that aren’t that the same as if I type the field names manually

    What is the purpose of that aren’t that the same as if I type the field names manuallyYes it is written.

  • Factored SubQuery to insert data

    Hello,
    I am trying to use a Factored SubQuery to insert data.. I am getting the following error:
    Error report:
    SQL Error: ORA-00928: missing SELECT keyword
    00928. 00000 - "missing SELECT keyword"
    Below is an example of what I am trying to do.
    Thanks, sck
    WITH
    fsqAcutals AS
    SELECT
    Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code,
    SUM(CASE WHEN Ttime.Quarter = '1' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q01,
    SUM(CASE WHEN Ttime.Quarter = '2' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q02,
    SUM(CASE WHEN Ttime.Quarter = '3' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q03,
    SUM(CASE WHEN Ttime.Quarter = '4' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q04
    FROM TIME Ttime INNER JOIN Sales_Actuals Trev ON Ttime.Time_Code = Trev.Time_Code
    WHERE
    (Trev.Is_Active = 'Y') AND (Ttime.Year = '2007') AND
    (Trev.Account_Code IS NOT NULL) AND (Trev.Sub_RSC_Code IS NOT NULL) AND (Trev.BD_Code IS NOT NULL)
    GROUP BY Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code
    fsqTarget AS
    SELECT
    Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code,
    SUM(CASE WHEN Ttime.Quarter = '1' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q01,
    SUM(CASE WHEN Ttime.Quarter = '2' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q02,
    SUM(CASE WHEN Ttime.Quarter = '3' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q03,
    SUM(CASE WHEN Ttime.Quarter = '4' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q04
    FROM TIME Ttime INNER JOIN Sales_Target Trev ON Ttime.Time_Code = Trev.Time_Code
    WHERE
    (Trev.Is_Active = 'Y') AND (Ttime.Year = '2007') AND
    (Trev.Account_Code IS NOT NULL) AND (Trev.Sub_RSC_Code IS NOT NULL) AND (Trev.BD_Code IS NOT NULL)
    GROUP BY Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code
    INSERT INTO Stage_Report_Revenue
    (Revenue_Year, Forecast_Flag, Account_Code, Sub_RSC_Code, BD_Code,
    Actuals_Q01, Actuals_Q02, Actuals_Q03, Actuals_Q04, Target_Q01)
    SELECT
    Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code,
    Actual_Q01, Actual_Q02, Actual_Q03, Actual_Q04, Ttgt.Target_Q01
    FROM
    fsqAcutals Tact
    LEFT JOIN fsqTarget Ttgt ON
    (Tact.Year = Ttgt.Year) AND
    (Tact.Account_Code = Ttgt.Account_Code) AND
    (Tact.Sub_RSC_Code = Ttgt.Sub_RSC_Code) AND
    (Tact.BD_Code = Ttgt.BD_Code);
    COMMIT;

    If I recall correctly it should be -
    INSERT INTO Stage_Report_Revenue
    (Revenue_Year, Forecast_Flag, Account_Code, Sub_RSC_Code, BD_Code,
    Actuals_Q01, Actuals_Q02, Actuals_Q03, Actuals_Q04, Target_Q01)
    WITH
    fsqAcutals AS
    SELECT
    Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code,
    SUM(CASE WHEN Ttime.Quarter = '1' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q01,
    SUM(CASE WHEN Ttime.Quarter = '2' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q02,
    SUM(CASE WHEN Ttime.Quarter = '3' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q03,
    SUM(CASE WHEN Ttime.Quarter = '4' THEN COALESCE(Trev.Actuals_Amount, 0) ELSE 0 END) AS Actual_Q04
    FROM TIME Ttime INNER JOIN Sales_Actuals Trev ON Ttime.Time_Code = Trev.Time_Code
    WHERE
    (Trev.Is_Active = 'Y') AND (Ttime.Year = '2007') AND
    (Trev.Account_Code IS NOT NULL) AND (Trev.Sub_RSC_Code IS NOT NULL) AND (Trev.BD_Code IS NOT NULL)
    GROUP BY Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code
    fsqTarget AS
    SELECT
    Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code,
    SUM(CASE WHEN Ttime.Quarter = '1' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q01,
    SUM(CASE WHEN Ttime.Quarter = '2' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q02,
    SUM(CASE WHEN Ttime.Quarter = '3' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q03,
    SUM(CASE WHEN Ttime.Quarter = '4' THEN COALESCE(Trev.Target_Amount, 0) ELSE 0 END) AS Target_Q04
    FROM TIME Ttime INNER JOIN Sales_Target Trev ON Ttime.Time_Code = Trev.Time_Code
    WHERE
    (Trev.Is_Active = 'Y') AND (Ttime.Year = '2007') AND
    (Trev.Account_Code IS NOT NULL) AND (Trev.Sub_RSC_Code IS NOT NULL) AND (Trev.BD_Code IS NOT NULL)
    GROUP BY Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code
    SELECT
    Ttime.Year, Trev.Account_Code, Trev.Sub_RSC_Code, Trev.BD_Code,
    Actual_Q01, Actual_Q02, Actual_Q03, Actual_Q04, Ttgt.Target_Q01
    FROM
    fsqAcutals Tact
    LEFT JOIN fsqTarget Ttgt ON
    (Tact.Year = Ttgt.Year) AND
    (Tact.Account_Code = Ttgt.Account_Code) AND
    (Tact.Sub_RSC_Code = Ttgt.Sub_RSC_Code) AND
    (Tact.BD_Code = Ttgt.BD_Code);Any way, does the select alon (without the insert) works?
    Amiel Davis

  • Insert statement with subquery to insert multiple rows

    Hi frnds,
    Kindly find the below mentioned query and error. Also suggest me to go ahead.
    SQL>  INSERT INTO FM_TRAN_DOC_NO (TDOC_COMP_CODE,
      2                               TDOC_TRAN_CODE,
      3                               TDOC_ACNT_YEAR,
      4                               TDOC_CUR_NO,
      5                               TDOC_MAX_NO,
      6                               TDOC_CAL_YEAR,
      7                               TDOC_PERIOD,
      8                               TDOC_DIVN_CODE,
      9                               TDOC_DEPT_CODE,
    10                               TDOC_CR_UID,
    11                               TDOC_CR_DT,
    12                               TDOC_UPD_UID,
    13                               TDOC_UPD_DT)
    14     SELECT    '001',
    15               (SELECT DISTINCT TDOC_TRAN_CODE FROM FM_TRAN_DOC_NO
    16               '6',
    17               '0',
    18               '9999',
    19               NULL,
    20               NULL,
    21               NULL,
    22               NULL,
    23               'AGT',
    24               TO_DATE (SYSDATE),
    25               NULL,
    26               TO_DATE (SYSDATE) FROM DUAL;
                 (SELECT DISTINCT TDOC_TRAN_CODE FROM FM_TRAN_DOC_NO ),
    ERROR at line 15:
    ORA-01427: single-row subquery returns more than one row

    This "SELECT DISTINCT TDOC_TRAN_CODE FROM FM_TRAN_DOC_NO" query returns multiple rows. So what is your requirement?
    Try the below insert if you want to select from tale FM_TRAN_DOC_NO
    INSERT INTO FM_TRAN_DOC_NO (TDOC_TRAN_CODE,
                                TDOC_COMP_CODE,
                                 TDOC_ACNT_YEAR,
                                 TDOC_CUR_NO,
                                 TDOC_MAX_NO,
                                 TDOC_CAL_YEAR,
                                 TDOC_PERIOD,
                                 TDOC_DIVN_CODE,
                                 TDOC_DEPT_CODE,
                                TDOC_CR_UID,
                                TDOC_CR_DT,
                                TDOC_UPD_UID,
                                TDOC_UPD_DT)
      SELECT    DISTINCT
                TDOC_TRAN_CODE
                '001',
                '6',
                '0',
                '9999',
                NULL,
                NULL,
                NULL,
                NULL,
                'AGT',
                TO_DATE (SYSDATE),
                NULL,
                TO_DATE (SYSDATE) FROM TDOC_TRAN_CODE;
    Message was edited by: 000000

  • What is the purpose of the subquery at the end of a multitable insert?

    I am learning about multitable inserts and am confused about the required subquery at the end of the insert statement. Take the following for example:
    INSERT ALL
    INTO t1 VALUES('value1')
    INTO t1 VALUES('value2')
    SELECT 1 FROM DUAL;
    What is the subquery "SELECT 1 FROM DUAL" for? The subquery must be there; and it can be any select statement, not just the simple one I have here. Does the subquery simply act as a termination for the inserts?

    >
    INSERT ALL
    INTO t1 VALUES('value1')
    INTO t1 VALUES('value2')
    SELECT 1 FROM DUAL;
    What is the subquery "SELECT 1 FROM DUAL" for?It is there for returning a single row from DUAL. Oracle evaluates the rows returned by the subquery and executes each of those "INTO" clauses once for each row returned by the subquery.
    Thus, each of the "INTO ... VALUES" clause is evaluated once for that 1 row returned by DUAL.
    Alternatively, you could write just one "INTO...VALUES" clause and return multiple rows in the subquery, thusly:
    SQL>
    SQL> drop table t1;
    Table dropped.
    SQL> create table t1 (x varchar2(10));
    Table created.
    SQL>
    insert all
    into t1 values (x)
    select 'value1' as x from dual union all
    select 'value2'      from dual union all
    select 'value3'      from dual;
    3 rows created.
    SQL>
    SQL> select * from t1;
    X
    value1
    value2
    value3
    SQL>
    SQL>
    ... Does the subquery simply act as a termination for the inserts?Well, no. The semi-colon character (";") or a forward slash character ("/") on the first column of the last line acts as the SQL terminator.
    The subquery is there because Oracle needs some data to evaluate, process as per the conditions and insert into (one or more) tables.
    Check the link to the documentation where it is explained in detail:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#SQLRF01604
    isotope

  • Cannot insert data from local database into remote database using subquery

    I have two oracle databases on different host.
    One is version 8i in Host A and the other is 9i in Host B.
    First, I try to create a dblink in 8i to 9i, but it fail.
    Then, I create a dblink in 9i to 8i, it success.
    I have already tried some select statement in 9i to view the table in 8i, which is success and that means the dblink is really work.
    The sql statement is like
    Select * from table1@hostA
    Then I have tried running some INSERT statement in 9i, which is copy data from table 1 in 8i to table 2 in 8i, both tables are in 8i. The sql statement is like
    Insert INTO table2@hostA(field1, field2)
    select field1, field2
    from table1@hostA
    This also success.
    Also, I have tried to use the following INSERT statement
    Insert INTO table2@hostA(field1, field2) values ('XXX', 'XXX)
    This also success.
    However, when I try to insert data from table in 9i to table in 8i using the following INSERT statement, it failed.
    Insert INTO table2@hostA(field1, field2)
    select field1, field2
    from table1
    The statement can execute, but all the rows inserted with every field value equal to NULL. I have tried to run the select part, it can return the data. But when I run the INSERT statement above, the value inserted into table2 is all equal to NULL.
    One more thing, I discover that the databases are using different NLS_CHARACTERSET
    9i is AL32UTF8
    8i is WE8ISO8859P1
    Is this relevant to my problem?
    Does anyone know the solution about this problem?
    Thanks!!

    How is the best way to do this ?How much are you planning to send?
    You can use COPY command. Ensure that you have valid database link between two databases.
    Available options are:
    create - creates a new table. errors out if the destination table exists.
    replace - drop the destination table and re-creates with data.
    insert - inserts data if the destination table exists.
    append– appends data into an existing table.
    use set arraysize 5000 -The arraysize specifies the number of rows that SQL*Plus will retrieve from the database at one time.
    copy from scott/tiger@ORCL to scott/tiger@ORCL92 create new_emp using select * from emp;

  • How to INSERT into table using CORRELATED subquery

    I have 3 tables:
    1.TEMP_PHONE(person_id, phonenumber, phone_type) - this holds all phone numbers relating to a person(just a temporary holding area)
    2.PHONE_CONNECT(PERSON_ID, PHONE_ID) this table shows all the phone numbers relating to an individual. Phone_id is a unique number to identify a phonenumber and type(cell, work, home) - so in this table a person can have multiple phone ids)
    3.MASTER_PHONE(PHONE_ID, PHONENUMBER, PHONE_TYPE) this is a master phone table. each combination of phone number and type has a unique identifier-phone_id.
    What i need to figure out is how to populate PHONE_CONNECT with the information from TEMP_PHONE IF PERSON_ID already exists but phone_id is different. In other words, if the person gets a new phone number, i need to insert a new row into phone_connect.
    Before that step is started, the master_phone is populated first with a new phone_id associated to the phonenumber/type
    any help would be much appreciated. Thanks in advance.
    So far, this is what i have come up with, but not sure if it makes sense:
    insert into phone_connect(person_id)
    select a.person_id
    from temp_phone a
    where
    person_id = (select b.person_id from phone_connect b, master_phone c
    where
    a.person_id=b.person_id
    and b.phone_id <> c.phone_id
    and c.phonenumber||c.phone_type=a.phonenumber||a.phone_type);
    update phone_connect c
    set phone_id=(
    select b.phone_id
    from temp_phone a, master_phone b
    where a.person_id = c.person_id
    and a.phonenumber||a.phone_type = b.phonenumber||b.phone_type)
    where phone_id is null;

    It does. You are right. But that's what i need help with. I don't think my code is correct. After the insert, the code is actually updating the same exact record I just inserted. I'm sure this all can be done with one insert. I just really don't know how to show that in my code.
    I need to insert a new record into phone_connect with person_id and phone_id. phone_id is already populated in master_phone. I guess my problem is how to go about creating the joins to all three tables to make sure im inserting the data correctly, or not inserting data that already exists.

Maybe you are looking for

  • Upgrade Default Address Lists from LDAP

    Hello, I migrated from MS Exchange 2003 to 2010 some time back. Currently trying to upgrade the address lists as per the guide here: http://technet.microsoft.com/en-us/library/dd351283.aspx When I  run Set-GlobalAddressList "Default Global Address Li

  • Alpha numeric Sorting Issue with BIP-Siebel report

    Hi All, The report contains a column called 'Site Name' which contains alpha-number values such as '111 street', '4th Cross', 'Road cross', 'North end street' etc. The sorting expected here is in the form: 111 street 412 Cross North end street Road c

  • Multiple Instances of the Same Excel Document in 'Alt-Tab' List

    So I am having a very weird problem, and I can't seem to find an answer anywhere. I was recently given a new laptop at work with Windows 7 and Office 2010. It has worked pretty well so far, but recently I have been noticing something very strange. Wh

  • Intrastat Germany Free Goods comes error "invoice value to be filled"

    Hi Gurus, I am running Intrastat in GTS for Germany. For free goods we are entering the statistical value but invoice value must be zero, because these are free goods. But GTS does not allow a Zero value as invoice value. What to do? Please help Than

  • Screen turns pink and flickers

    Hi everyone, I've got a little problem: My screen randomly turns pinks and then starts flickering and then a few moments later it stops for a few minutes and then begins the process again.  I have no idea how it began. I have a MacBook Pro 10.6.8. It