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.

Similar Messages

  • 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;

  • 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
    ;

  • Using Subquery in Prepared Statement

    can i use subquery in my insert using prepared statement
    need to specify the * property
    eg: insert into table1 values(select * from table2)

    can i use subquery in my insert using prepared
    statement
    need to specify the * property
    eg: insert into table1 values(select * from table2)Subqueries are perfectly okay, of course, but I think the proper idiom is:
    INSERT INTO foo(a, b, c)
    SELECT x, y, z
    FROM bar
    WHERE  x = 'baz'MOD

  • 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.

  • Decode Function issue

    Hi all,
    i want compare two rows in a table. so i used decode function to compare the values, whether its matched or not.
    One of my table column has Long data type.
    Decode(a.col1,b.col1,'Match','NotMatch')
    col1 - is long data type.
    when i use long data type, i got below error,
    is there anyway to rectify this error.
    SQL Error: ORA-00932: inconsistent datatypes: expected NUMBER got LONG
    00932. 00000 - "inconsistent datatypes: expected %s got %s"
    Thanks in advance.
    Regards,
    Santhosh

    >
    You can't use ANY function on a LONG column. This restriction is not limited to DECODE.
    >
    Not quite correct.
    You can use TO_LOB on a LONG column but only in the select list of a subquery in an INSERT statement.
    See TO_LOB in the SQL Language doc
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions205.htm#SQLRF06134
    >
    TO_LOB converts LONG or LONG RAW values in the column long_column to LOB values. You can apply this function only to a LONG or LONG RAW column, and only in the select list of a subquery in an INSERT statement.
    Before using this function, you must create a LOB column to receive the converted LONG values. To convert LONG values, create a CLOB column. To convert LONG RAW values, create a BLOB column.
    You cannot use the TO_LOB function to convert a LONG column to a LOB column in the subquery of a CREATE TABLE ... AS SELECT statement if you are creating an index-organized table. Instead, create the index-organized table without the LONG column, and then use the TO_LOB function in an INSERT ... AS SELECT statement.
    You cannot use this function within a PL/SQL package. Instead use the TO_CLOB or TO_BLOB functions.

  • 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

  • Function to covert LONG to CLOB

    Can you please tell me the name of the function through which I can change the LONG datatype to CLOB.

    There is a function called to_lob(). You can use it only inside a subquery of an INSERT statement.
    Try doing something like this..
    1. Create an equivalent table except that instead of LONG use a CLOB datatype.
    2. Insert into that table using something like...
    INSERT INTO table_name SELECT a, b, to_LOB(long_column), c FROM original_table;
    3. DROP ur table and rename the other table.
    Or you can do some other trickery.
    Regards,
    Naveen

  • Accessing IMAGE Columns in SQL Server

    I'm trying to use the TG4MSSQL to access tables in a SS2k database. All is well, except for 1 table that has an IMAGE column in it. I must say that I'm a little surprised and disappointed that the 10gR2 gateway for MSSQL apparently translates these things into LONG RAW columns, which are known to be antiquated and minimally supported. However, I still need access to the data, and ultimately, I need it in a BLOB. Doing simple queries (in TOAD) such as:
    select * from image@tg4ss where image_id = 1;
    returns the row, and I can use TOAD to determine that all the data is there. However, apparently, you cannot use PL/SQL to bind more than 32K of this data into a variable, so I haven't had much success there.
    The only way I know of converting a long raw to a blob is to use the to_lob function, but that's only good in the select list of a subquery of an insert statement. Thing is, that doesn't seem to work with the gateway. I tried something like:
    insert into my_blob_table( id, image )
    select id, to_lob(image) as image from image@tg4ss where id = 1;
    That gets me a ORA-00997: illegal use of LONG datatype.
    In fact, I can't even do this:
    insert into my_long_raw_table( id, image )
    select id, image from image@tg4ss where id = 1;
    I get the same error on that command.
    Now, I can do this, but I only get the first 32k of the image:
    begin
    for I in (select id, image from IMAGE@tg4ss)
    loop
    insert into my_long_raw_table( id, image )
    values (I.id, I.image);
    end loop;
    end;
    So, does anyone know how you can get image data out of an SQL Server database into a blob value? If so, I'd appreciate a reply. Thanks.
    -Rich.

    Hello Rich,
    I found your article after running into the same problem. I imagine you've dealt with this one way or another already but just in case...
    The reason the LONG RAW gets truncated is explained in:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/datatypes.htm#i43252
    Basically, LONG RAW variables are limited to 32760 bytes inside PL/SQL. The ORA-00997 error is explained a little in:
    http://www.dbaxchange.com/3_4_longdatatypes.htm
    The only solution I found to work was to create a Java utility that read in each LONG RAW value (one at a time) and then update a record in a table's BLOB column. This was even a bit tricky. I found the gateway would lock up if I tried to do too much at a time. I kept it simple my reading all column IDs into an array and then looping through the array while executing a simple select statement that retrieved the LONG RAW value. I concatenated the id to the end of the select statement because prepared statements seemed to be one of the reasons the gateway locked up. I used a ByteArrayInputStream object to populate the BLOB in an update prepared statement for each LONG RAW value processed in the loop.
    - Aaron

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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

  • 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

Maybe you are looking for

  • ITunes (Windows) does not quit properly

    Closing windows version using "x" at top right corner of screen or selecting Exit from file menu makes iTunes clear the screen, but it's still runnning. I have to do a ctrl-alt-del and then manually quit the process tree. Otherwise, re-clicking on th

  • How to call workflow approve service in loop for multiple documents.

    i have created a serviceHandler for approving the document and i post the comma separated dIDs as a string from workflow approval template(custom template). And in serviceHandler program i pass the did for approving and only first document is approve

  • How to capture path and file info in a JSP?

    Hi, I am developing an JSP in which I am trying to capture the path and file name that I can then write into a database entry. For example in MS word when you do file > open a box pops up that you can navigate to the required folder and then click on

  • My router only recognise 1 iPad at a time.

    When my daughter comes round with her iPad, she gets on to the internet no prob on our router, but my ipad will then immediately loses its connection. When she switches her iPad off, mine goes back online. How to I fix it so that the router can deal

  • Slideshow in GoLive

    Daverj... Is there a way to add transitions to your actions? Also, for anyone... Is it possible to insert an .exe into GoLive for slideshows? I have a very good program called Pic to .exe and it creates very nice shows. Plus I have Lightroom which al