Insert using select

Hi,
I am using 10g. And there is a wierd problem. When I run the query I get say 10 rows; ,but when I use the same query to insert into a table, I get unpreditable number of rows inserted into the result table.
select a.col1, a.col2, c.col3 from a, b, c
where a.col1 = b.col2
and b.col1=c.col2
union all
select x.col1, y.col2, z.col3 from z, y, z
where z.col1 = y.col2
and y.col1=z.col2
retruns 10 rows
insert into yy
select a.col1, a.col2, c.col3 from a, b, c
where a.col1 = b.col2
and b.col1=c.col2
union all
select x.col1, y.col2, z.col3 from z, y, z
where z.col1 = y.col2
and y.col1=z.col2
inserts 6 rows...
Any idea why? We are about to request the DBA for a DB restart. Appreciate any help.

No. no triggers or constraints on the table. not even "not null" constraint.
i found another behaviour, which I am not sure would help find the cause...
Strangely enough, when I move the table to a different tablespace and run the insert it seems to be working fine for some time, but after that again the same wierd behaviour was encountered. When I try to do explain plan it is completely same with and without the insert. For now, we are using pl/sql for loop and inserting record by record. It will not be ideal if the data get's bigger.

Similar Messages

  • Number of rows inserted is different in bulk insert using select statement

    I am facing a problem in bulk insert using SELECT statement.
    My sql statement is like below.
    strQuery :='INSERT INTO TAB3
    (SELECT t1.c1,t2.c2
    FROM TAB1 t1, TAB2 t2
    WHERE t1.c1 = t2.c1
    AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
    EXECUTE IMMEDIATE strQuery ;
    These SQL statements are inside a procedure. And this procedure is called from C#.
    The number of rows returned by the "SELECT" query is 70.
    On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
    But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
    And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
    On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
    Anybody faced these kind of issues?
    Can anyone tell what would be the reason of this issue..? any other work around for this...?
    I am using Oracle 10g R2 version.
    Edited by: user13339527 on Jun 29, 2010 3:55 AM
    Edited by: user13339527 on Jun 29, 2010 3:56 AM

    You have very likely concurrent transactions on the database:
    >
    By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
    >
    If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
    Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
    You can try to run your test with:
    set  transaction isolation level  serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
    like:
    wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46

  • Insert using select statement

    Hi,
    I am trying to insert values using select statement. But this is not working
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    VALUES
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;
    Please let me know what i am missing..
    Thanks
    Sudhir

    Try this
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;Note: when you are selecting a value using select statement, you should not specify the keyword "values".
    i assume you have already assigned value for your bind variable :P1_PROJECTS and rest of the functions will return some value.
    Regards,
    Prazy

  • Insert Using SELECT & Sub-SELECT

    Hi All,
    I am trying to insert records into a table using SELECT statement. The SELECT statement has a Sub-SELECT statement as follows:
    INSERT INTO table1(c1,c2,c3,c4,c5)
    SELECT c1,c2, (SELECT MAX(C3)+a1.c3
    FROM table1
    WHERE c1 = var1
    AND c2 = a1.c2
    GROUP BY c3),c4,c5,
    FROM table1 a1
    WHERE c1 = var1
    The above works fine when run from SQL*PLUS but gives compilation error when included in PL/SQL pacakge.
    I am using Oracle 8.1.7.
    Could you any one please tell me if I have missed something?
    Thanks,
    Satyen.

    In 8i, you will need to use dynamic SQL to execute this statement because the PL/SQL parser does not understand all SQL syntax (including SELECT in a column list).
    execute immediate
      'INSERT INTO table1(c1,c2,c3,c4,c5)' ||
      ' SELECT c1, c2, (SELECT MAX(C3)+a1.c3 FROM table1 WHERE c1 = :var1 AND c2 = a1.c2 GROUP BY c3), c4, c5' ||
      '   FROM table1 a1 WHERE c1 = :var1' using var1, var1;

  • DYNAMIC QUERY FOR INSERT USING SELECT

    Hi All,
    I am facing an issue...I am un bale to do an dynamic query. i have explained my code and the sample create, insert statements. I shud insert values in a table using a select statement dynamically..
    create table listing (tel_no varchar2(16), list_key varchar2(30));
    create table dummy_extract ( extract_name varchar2(10),extract_query varchar2(400),extract_date date );
    create table dummy_query (tel_no varchar2(16), list_key varchar2(30));
    insert into listing (tel_no ,header_key) values ('123456','123.23');
    insert into dummy_extract (extract_name,extract_query,extract_date) values ('SP','SELECT TEL_NO, LIST_KEY FROM LISTING','10-DEC-2010');
    SET SERVEROUTPUT ON
    declare
    CURSOR CUR_QUERY IS
    SELECT * FROM DUMMY_EXTRACT ;
    V_STMT VARCHAR2(4000);
    BEGIN
    FOR I IN CUR_QUERY LOOP
    V_STMT := 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
    EXECUTE IMMEDIATE V_STMT using i.extract_query;
    DBMS_OUTPUT.PUT_LINE (V_STMT);
    END LOOP;
    END ;

    Hi Blue shadow and Saubik,
    I tried my query.It shows missing expression...Could you tell me the reason...
    SET SERVEROUTPUT ON
    declare
    CURSOR CUR_QUERY IS
    SELECT * FROM DUMMY_EXTRACT ;
    V_STMT VARCHAR2(4000);
    BEGIN
    FOR I IN CUR_QUERY LOOP
    --V_STMT := 'INSERT INTO'|| DUMMY_QUERY ||'VALUES ' ||(I.EXTRACT_QUERY ) ;
    EXECUTE IMMEDIATE 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
    DBMS_OUTPUT.PUT_LINE (V_STMT);
    END LOOP;
    END ;
    Error report:
    ORA-00936: missing expression
    ORA-06512: at line 14
    00936. 00000 - "missing expression"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • INSERT INTO TABLE using SELECT takes long time

    Hello Friends,
    --- Oracle version 10.2.0.4.0
    --- I am trying to insert around 2.5 lakhs records in a table using INSERT ..SELECT. The insert takes long time and seems to be hung.
    --- When i try to SELECT the query fetches the rows in 10 seconds.
    --- Any clue why it is taking so much time

    vishalrs wrote:
    Hello Friends,hello
    >
    >
    --- Oracle version 10.2.0.4.0
    alright
    --- I am trying to insert around 2.5 lakhs records in a table using INSERT ..SELECT. The insert takes long time and seems to be hung.
    I don't know how a lakh is, but it sounds like a lot...
    --- When i try to SELECT the query fetches the rows in 10 seconds.
    how did you test this? and did you fetch the last record, or just the first couple of hundred.
    --- Any clue why it is taking so much timeWithout seeing anything, it's impossible to tell the reason.
    Search the forum for "When your query takes too long"

  • Insert with Select while Using Merge

    Actual Query
    MERGE INTO schema1.employees D
       USING (SELECT employee_id, salary, department_id FROM schema2.employees
       WHERE department_id = 80) S
       ON (D.employee_id = S.employee_id)
       WHEN MATCHED THEN
       UPDATE
       SET D.bonus = D.bonus + S.salary*.01
       WHERE (S.salary > 8000)
       WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
       VALUES (S.employee_id, S.salary*.01)
       WHERE (S.salary <= 8000) Is there a possible way to write a select Query in Insert Statement while using Merge.
      WHEN NOT MATCHED THEN
       INSERT
       SELECT * FROM schema2.employees
       WHERE S.salary <= 8000;

    it works:
    MERGE INTO fifapps.tes2
    using dual
    on (1=2)
    when not matched then insert values(59,'yes');
    commit;or
    MERGE INTO fifapps.tes2
    using dual
    on (1=2)
    when not matched then insert values ((select 99 from dual),(select'weii' from dual));
    commit;Edited by: ʃʃp on Jun 13, 2012 2:03 AM
    Edited by: ʃʃp on Jun 13, 2012 2:03 AM

  • How to get the inserted row primary key with out  using select statement

    how to return the primary key of inserted row ,with out using select statement
    Edited by: 849614 on Apr 4, 2011 6:13 AM

    yes thanks to all ,who helped me .its working fine
    getGeneratedKeys
    String hh = "INSERT INTO DIPOFFERTE (DIPOFFERTEID,AUDITUSERIDMODIFIED)VALUES(DIPOFFERTE_SEQ.nextval,?)";
              String generatedColumns[] = {"DIPOFFERTEID"};
              PreparedStatement preparedStatement = null;
              try {
                   //String gen[] = {"DIPOFFERTEID"};
                   PreparedStatement pstmt = conn.prepareStatement(hh, generatedColumns);
                   pstmt.setLong(1, 1);
                   pstmt.executeUpdate();
                   ResultSet rs = pstmt.getGeneratedKeys();
                   rs.next();
    //               The generated order id
                   long orderId = rs.getLong(1);

  • Locking problem w/ INSERT..SELECT using sequences.

    I have a scenario where an INSERT..SELECT statement that includes incrementing a sequence value is causing Exclusive DX locks on the SYS.I_SEQ1 index and the SYS.RESOURCE_COST$ table. When the statement is executing from within a COM+ application using distributed transactions the behavior is exhibited. If the same statement is executed from SQLPlus these locks are not acquired. The statement is similar to:
    insert into table1 ( pkey, column2)
    select pkey_seq.nextval, value2
    from table2;
    Anyone have any idea why this behavior is seen in a distributed transaction?
    Thanks,
    Sam

    Hi Ari,
    Thanks for the tip. I noticed that approach in earlier posts, but these people were using Oracle 9 and below. The feature I am trying to use is a JDBC 3.0 feature and I believe was introduced in recent JDBC drivers (10.1.0).
    I suspect the driver inserts a RETURNING clause anyway. I got this impression from this post (mid-way down the first paragraph):
    http://archives.postgresql.org/pgsql-jdbc/2003-05/msg00040.php
    Although this post is about to postgresql's JDBC driver, I guess the Oracle driver would probably do a similar thing? If so, then the problem I am having could be that the final SQL (my SQL + inserted RETURNING clause) is invalid.
    Anyway, I don't have a problem with this anymore because I changed my design (for the better) and I don't have to do the insert select statement.
    Regards,
    Simon.

  • Querying for a script insert multiple selected objects...

    Is there a script or plugin which insert multiple selected objects in one new text frame with one click?
    And is there a script or plugin which extract the content of anchored text frame out it's frame and replace it with it's frame. and extract selected text and insert it inside a new anchored text frame in it's place? (like convert text to table - convert table to text, but instead table we use text frame)

    Hi,
    Using OMB scripting to set attribute properties in a data mapping sort of defeats the purpose of utilizing a graphical user interface to define and set properties for a data mapping? Surely the GUI data mapping tool was created to get away from writing scripts and scripting would also require that you know the name of the data mapping, table operator and the set of attribute names for which you have to write one line of script to set each property value, i.e. 90 lines to set 90 attribute values.
    Cheers,
    Phil

  • How to pass parameter in Function by using select statement?

    Hi,
    I got a problem. I cant pass in parameter to function by using select statement. But it can pass in parameter by using 'hardcode' method. How can I solve this problem?
    Eg,
    select * from table (SplitFunction('HS750020,HS750021')) <<< this work.
    but
    select * from table (SplitFunction(select LOT_NO from TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) <<< do not work.
    Thanks for who try to help. Thanks.

    skymonster84 wrote:
    I have try this before. But it not work.here is an example
    create or replace type stringlist as table of varchar2(100)
    create or replace function splitstring(pstring in varchar2) return stringlist
    as
      lstringlist stringlist;
    begin
      select regexp_substr(pstring,'[^,]+',1, level) bulk collect into lstringlist
        from dual
      connect by level <= length(pstring)-length(replace(pstring,','))+1;
      return lstringlist;
    end;
    select * from table(select splitstring('xx,yy,zz') from dual)
    create table t(str varchar2(100))
    insert into t values('x,y,z')
    insert into t values('a,b,c')
    select * from table(select splitstring(str) from t where rownum<2)
    /If you supply multiple values then it will fail.
    select * from table(select splitstring(str) from t)
    /

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

  • Using SELECT INTO statement to transfer data from one DB to another?

    Hello,
    I need to move data from an SAP table to another downstream SQL server box without flat file in between. I have set up the DBCON interface, so that my ABAP code on SAP can connect to the remote SQL Server, then I can run INSERT command as Native SQL inside the ABAP.
    However, INSERT has performance problem. The best performer as I can find is SELECT INTO statement. But then I am stuck at how to use SELECT INTO to query my local SAP table and send (via INTO) to remote database. I am not even sure whether I should use Open SQL or Native SQL.
    Any suggestion? BTW, I understand the limitation of Native SQL, but we are OK to use it.
    Thanks!

    It appears that this is some kind of migration project due to the scope of the data contained in the single file? If so whatever you do is like ly to be trow away once the migration of data is completed.
    You have a couple of options:
    1) Get the data extracted from HFM in multiple files instead of one bulk file, broken down by scanario,year & period
    2) Take the single data dump file produced by FDM and manipulate it yourself to get the data in a more usuable format for processing through FDM.
    Option 2 could be achieved via any ETL tool or a custom file parsing script. What may be more attractive to you and allow you to fully leverage your investment in FDM is that you could use the PULL adapter that ships as part of the FDM adapter suite to perform this transformation exercise. The PULL adapter takes a flat file input and allows you to use all the in built functionality of FDM to transform it and output a modified flat file (or series of flat files). You could use it to produce multioload files or a series of files broken down by scenario,year,period.
    Whatever you do I would suggest that break the single data file down into smaller chunks as this will help with the iterative debugging process you will inevitably have to undetake whislt migrating the data to the new application.

  • A query with "insert..select" run with dqp?

    I would like to know if a query with "insert cluase select clause" is operated with the function of the dqp.
    I think that a query portion with "select clause" is possible to run with dqp.
    if anybody knows about this case, please let me know.
    Thanks in advance,
    Dokon Kim

    There is no such thing as pl/sql 5.1.4, at that time pl/sql didn't even exist.
    You also state it works in Sql*plus but it doesn't work in PL/SQL as PL/SQL is using OCI7. Which isn't true.
    Please stop playing games and withhelding information.
    Post the real info. Not what you think is important.
    Why are you using a (desupported) 9.0.1 client against a 10GR2 database?}
    Sybrand Bakker
    Senior Oracle DBA

  • Using select * in pl/sql

    Hi,
    Yesterday Karthick mentioned that using SELECT * in PL/SQL is not a good idea. But I tried by creating a table and different procedures with selecting all columns using * and specifying the columns individually. Later I altered the table and both procedures became invalid. Can some one give a simple example to demonstrate the behaviour.
    At present I dont have Oracle in my PC to post what I have tried yesterday.
    Cheers,
    Suri

    When I run the following script, the 2nd time the test1 procedure runs, it fails with "PLS-00905: object TEST1 is invalid", whereas test2 runs fine both times.
    Feel free to try it yourself!
    create table boneist_test (col1 number, col2 varchar2(10));
    insert into boneist_test values (1, 'a');
    commit;
    create procedure test1
    is
      v_num number;
      v_var varchar2(10);
    begin
      select *
      into v_num, v_var
      from boneist_test
      where rownum = 1;
    end test1;
    create procedure test2
    is
      v_num number;
      v_var varchar2(10);
    begin
      select col1, col2
      into v_num, v_var
      from boneist_test
      where rownum = 1;
    end test2;
    begin
      test1;
    end;
    begin
      test2;
    end;
    alter table boneist_test add (col3 number);
    begin
      test1;
    end;
    begin
      test2;
    end;
    drop table boneist_test;
    drop procedure test1;
    drop procedure test2;

Maybe you are looking for