Oracle 10g - Insert in to Temporary Table - Record count mismatch between s

We are trying insert records from a select query in to temporary table, some of the records is missing in the temporary table. The select statement is having multiple joins and union all which it little complex query. In simple terms the script contains 2 part 1st Part Insert in to temporary table 2nd part Select query with multiple joins, inline sub queries, unions and group by classes and conditions
Eg. If we execute select statement alone it returns some count for example => 60000 After inserting into the temp table, in temp table the count is around 42000 why is the difference?
It is simple bulk inserts... insert in to temp table select from xxx. also, there is no commit in between. The problem is all the records populated by the select statement are not inserted in to temp table. some records are not inserted.*
Also, we had some other observation. It only happens in its 2nd execution and not its first run. Hope there might be some cache problem
Even, we also did not believe that. We are wondering. In TOAD, we tested however at times it happens. In application jar file, after "insert in to temp select * from xxx" we take the i. record count of temp table and ii. record count of "select * from xxx" separately but both doesn't match. Match only at 1st time.
Thank you in advance for your efforts and help.
Shiva.

The code looks like
sql = "insert in to temptable select x,y,z,.... from xxx,abc,pqr..where...."; (logial but not real is very complex around 700 lines with multiple joins, inline sub queries, group by etc. )
stmt = conn.createStatement();
rCount= stmt.executeUpdate(sql);
Actual issue is
rCount = xxxx = Count(temptable) < count(select x,y,z,.... from xxx,abc,pqr..where....)
why this diffference ? some records populated in the select but not inserted in to temp table
Anyone can explain?

Similar Messages

  • Oracle 10g - issue with "DELETE from TABLE WHERE ID in (1,2,3)" (cfqueryparam used)

    Hello, everyone.
    I am having issues with running a DELETE statement on an Oracle 10g database.
    DELETE
    FROM tableA
    WHERE ID in (1,2,3)
    If there is only one ID for the IN clause, it works.  But if more than one ID is supplied, I get an "SQL command not properly ended" error message.  Here is the query as CF:
    DELETE
    FROM TRAINING
    WHERE userID = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#trim(form.userID)#">
         AND TRAINING_ID in <cfqueryparam value="#form.trainingIDs#" cfsqltype="CF_SQL_INTEGER" list="yes">
    Anyone work with Oracle that can help me with this?  I'm an experienced MS-SQL developer; Oracle is new to me.
    Thanks,
    ^_^

    Nevermind.. a co-worker just told me that I still have to use parenthesis around the values for the IN clause. 

  • We are upgrading from 8.3 to 9.2. How can i get the table(record) structure changes between these 2 version

    We are upgrading from 8.3 to 9.2. How can i get the table(record) structure changes between these 2 versions. I am not able to find it in Oracle support.

    My guess is you want to upgrade HR8.3 to 9.2 - and that is not one jump upgrade. You will need to go HRMS 83 to 90
    (PeopleSoft Enterprise HRMS 8.3x to 9.0 Upgrade (Doc ID 747333.1) and then 90 to 92 (PeopleSoft Human Capital Management 9.0 to 9.2 Upgrade Home Page (Doc ID 1536087.1)
    Each these MOS pages contains the Demo to Demo Compare Reports that show the data structures changes between the releases.
    Hope it helps.

  • Oracle 10g - Insert value into a self-created table in stored proc

    Hi all,
    Say I'm creating a table using the following logic,
    pc_create_table := 'create global temporary table revs(var1 number(5,0), ..., ...,) on commit preserve rows';
    execute immediate pc_create_table;
    When I'm attempting to insert value into this table (v_var1 is a pre-defined variable),
    pc_insert_value := 'insert into revs(var1, ..., ...,) values (v_var1, ...)'
    execute immediate pc_insert_value;
    I got the following error: "ORA-00984: column not allowed here"
    Any advise on this issue? Thanks a lot

    isaacniu wrote:
    However I got two errors in that line,
    Error(68,6): PL/SQL: SQL Statement ignored
    Error(68,18): PL/SQL: ORA-00942: table or view does not existAnd why do you want your PL/SQL code to run DDLs??
    Its not designed that way, is not a good practice and is strictly not recommended. You can read <a href ="https://forums.oracle.com/forums/profile.jspa?userID=287238">Billy Verreynne's</a> take on this :
    {message:id=10040770}
    To my suprise it's saying the table or view does not exist. According to my logic, the table "revs" created by executing pc_create_table, however it's NOT explicitly declared in other parts of this script, is this where the problem is?The Problem is, SQLs fired using Execute Immediate are evaluated, compiled, parsed and executed at run time. So when you compile procedure pc_create_table, table revs is still not created. Hence you get error when you try inserting rows in it.
    Any advises are appreciated.Get the table created by your DBA, and use insert statement without execute immediate in your procedure.

  • Oracle 10g Insert query performs inconsistent as a query vs procedure and p

    Database Version: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    No error messages....
    I am facing a very weird issue that I have a insert statement in a procedure... pretty much
    inert
    into oracle_Table
    SELECT cr.a AS a,
    cr.b AS b,
    cr.c AS c,
    max(d.column_name) as d
    FROM "table 1"@Pmo.World Cr,
    [email protected] d
    WHERE d."a" = cr."column name"
    GROUP BY cr.a,
    cr.b,
    cr.c
    @Pmo.World is a database link to a MSSQL...
    The problem I am having right now is, every time I run this insert as a query. Everything works as what it should be... However, when I put this insert into a procedure, it inserts nothing...
    Simple test Proceudre:
    declare
    -- Local variables here
    i integer;
    begin
    inert
    into oracle_Table
    SELECT cr.a AS a,
    cr.b AS b,
    cr.c AS c,
    max(d.column_name) as d
    FROM "table 1"@Pmo.World Cr,
    [email protected] d
    WHERE d."a" = cr."column name"
    GROUP BY cr.a,
    cr.b,
    cr.c
    end;
    Thinking about character conversion issue I changed the procedure to
    inert
    into oracle_Table
    SELECT to_char(cr.a) AS a,
    to_char(cr.b) AS b,
    to_char(cr.c) AS c,
    max(d.column_name) as d
    FROM "table 1"@Pmo.World Cr,
    [email protected] d
    WHERE d."a" = cr."column name"
    GROUP BY cr.a,
    cr.b,
    cr.c
    Then this Inser works in the procedure... however when I revert it back with the original version that doesnt have to_char... it is working still... then I kept it running for few days... since it runs once per day, it was working for the first 2 days and then stopped working the third day... I verified the source table and every time this procedure runs, source tables were not empty...
    It is so confusing because if I manually run the insert as a query, it worked every time I ran it... however if I put that into a procedure, it works from time to time..
    Any help is highly apprecaited
    Edited by: 986006 on Feb 4, 2013 8:51 AM

    986006 wrote:
    Thanks for the hints up... I have updated my post... As I post the test procedure...it is about the exact the same as the insert query... Every time, the insert would actually insert data into the table but every time I run the test procedure, nothing gets inserted in... It sounds unbelievable but it happens... ThanksYou obviously haven't read the FAQ, or at least you haven't bothered doing what it asks. Help us to help you.
    Can you recreate the problem with simpler data on your local machine? If so provide create table and insert statements for test data.
    Format your code and place between tags.
    At the very least post the *exact* SQL or PL/SQL you are trying to run: what you've posted isn't even valid SQL.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Oracle 10G R2: Cannot access a table whose name is a reserved keyword

    Hello,
    Oracle 10G R2 database being accessed using Oracle 10G thin driver in Java.
    There is a table named GROUP in the db - GROUP is a reserved keyword of course.
    When I execute the statement (after getting the database metadata object from a java.sql.Connection to the DB):
    oracle.jdbc.OracleDatabaseMetaData.getIndexInfo(null, "MYDB", "GROUP", false, true)
    I get:
    Exception in thread "main" java.sql.SQLException: ORA-00903: invalid table name
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
    at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:946)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
    at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1606)
    at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1571)
    at oracle.jdbc.OracleDatabaseMetaData.getIndexInfo(OracleDatabaseMetaData.java:3485)
    When I execute the statement:
    oracle.jdbc.OracleDatabaseMetaData.getIndexInfo(null, "MYDB", "\"GROUP\"", false, true)
    the result set is empty
    What is the correct way for me to get the index info from the table named GROUP?
    Thanks,
    Sundeep

    user5486925 wrote:
    oracle.jdbc.OracleDatabaseMetaData.getIndexInfo(null, "MYDB", "\"GROUP\"", false, true)
    the result set is empty
    Which would suggest you are using the correct name as a quoted identifier. Presumably the code you are using works for other tables. But you might try variations in case.
    You can also query the database directly to get the index information rather than using the metadata.
    What is the correct way for me to get the index info from the table named GROUP?The correct way is to not use reserved words.

  • How to Insert into a temporary table

    Hi Experts,
    I have created a temp table in sql from vfp using the #prefix. But when I issue an insert command sqlexec returns negative.
    The code which I have used :
    =sqlexec(oConn, "Create table #smenu (code_ varchar(1), name_ varchar(50))")
    Table created successfully under tempdb database of sql
    m_result=sqlexec(oConn, "insert into #smenu values ('100','Police')")
    m_result returns negative.
    Kindly help.

    Try to create a permanent table:
    =sqlexec(oConn, "Create table temp_smenu (code_ varchar(1), name_ varchar(50))")
    m_result=sqlexec(oConn, "insert into temp_smenu values ('100','Police')")
    Temporary table has limited visibility.
    You need to drop table temp_smenu when finished.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Slow Insert APPEND into Temporary Table

    Hello,
    We did the following test on Oracle11g 11.1.0.7 database:
    create global temporary table test_tab
    as select * from tab1 where rownum <= 1;
    insert into test_tab select * from tab1 where rownum <= 500000;
    commit;
    Elapsed time: 00:00:04.56
    Statistic
    80 recursive calls
    26360 db block gets
    10606 consistent gets
    4729 physical reads
    2543400 redo size
    399 bytes sent via SQL*Net to client
    340 bytes received via SQL*Net from client
    6 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    500000 rows processed
    truncate table test_tab;
    insert /*+ append */ into test_tab select * from tab1 where rownum <= 500000;
    commit;
    Elapsed time: 00:00:09.35
    Statistic
    84 recursive calls
    4900 db block gets
    4738 consistent gets
    4698 physical reads
    1128 redo size
    376 bytes sent via SQL*Net to client
    354 bytes received via SQL*Net from client
    6 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    500000 rows processed
    Note that insert APPEND generates much less redo size: 1128 vs 2543400 . Now the question: why insert APPEND into the temporary table is two times slower than the ordinary insert? Potentially, it should run faster because of lower redo size... Any ideas?

    If you run the truncate / insert / truncate / insert append again are the timings the same ?
    Wondering if the temp tablespace needed to extend for the first append.

  • Inserts into Global Temporary Table

    I'm working on using a global temporary table in one of my apps. I have a small test run here to isolate the problem. It simply creates the global temporary table, inserts a row, commits and then does a select to see if the insert worked. No data shows in the table when running this. I don't know much about global temp tables, so any help would be appreciated.
    CREATE GLOBAL TEMPORARY TABLE AGENT_SILO.AS_TEMP_VALIDATE (
    SBI_EMPLOYEE_ID NUMBER,
    CURRENT_FLAG char(1),
    EFFECTIVE_START date,
    EFFECTIVE_END date
    ) ON COMMIT DELETE ROWS;
    INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
    VALUES(0, '', SYSDATE, SYSDATE);
    commit;
    SELECT * FROM AGENT_SILO.AS_TEMP_VALIDATE;

    So I wonder what else I'm doing wrong that's really obvious. Here's what i'm trying to accomplish and maybe there's a better way of going about it.
    I have a trigger that is supposed to do some validation before the insert is allowed to go through. So here's my approach. I have a trigger fired when there's an insert into the AS_Employee_history table. This passes some of the fields from this insert into a proc (the id, a flag and a couple of dates). Within the proc, i create a global temp table, insert these passed values into the temp table. Then I have a cursor to basically copy the rows from the as_employee_history table that have the same id. Then I can do some selects on the temp table to see if it passes the validation.
    I have outputs throughout for debugging and it gets to right after the inserts into the temp table, then the rest of the code doesn't appear to be executed. So it looks like it's failing at the execution of select statements on the temp table. Anything else obvious that I"m missing here?
    Here's my proc.
    PROCEDURE "PAS_VALIDATE" (STATUS OUT VARCHAR2, v_status OUT BOOLEAN, NEW_SBI_EMPLOYEE_ID IN NUMBER,
    NEW_CURRENT_FLAG IN CHAR, NEW_EFFECTIVE_START IN DATE,
    NEW_EFFECTIVE_END IN DATE)
    IS
    v_prev_effective_end date;
    v_flag_count number;
    v_flag_count_date number;
    --variables to store dynamic sql returns
    v_sql_flag_count_date varchar2(255);
    v_sql_flag_count varchar2(255);
    v_sql_prev_eff_end varchar2(255);
    cursor c_row is
    select * from AGENT_SILO.AS_EMPLOYEE_HISTORY EMP
    where (EMP.SBI_EMPLOYEE_ID = NEW_SBI_EMPLOYEE_ID);
    r_row c_row%ROWTYPE;
    BEGIN
    Status := 'Started';
    v_status := true;
    DBMS_OUTPUT.PUT_LINE('Creating temporary table...');
    execute immediate 'CREATE GLOBAL TEMPORARY TABLE AGENT_SILO.AS_TEMP_VALIDATE (
    SBI_EMPLOYEE_ID NUMBER,
    CURRENT_FLAG char(1),
    EFFECTIVE_START date,
    EFFECTIVE_END date
    ) ON COMMIT PRESERVE ROWS';
         DBMS_OUTPUT.PUT_LINE('Validating the data...');
         --DBMS_OUTPUT.PUT_LINE('Inserting submitted row into temp table');
    --Insert the new row being submitted from user into the temp table
    execute immediate 'INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
    VALUES(' || NEW_SBI_EMPLOYEE_ID || ',
    ''' || NEW_CURRENT_FLAG || ''',
    to_date(''' || to_char(NEW_EFFECTIVE_START, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''),
    to_date(''' || to_char(NEW_EFFECTIVE_END, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''))';
    --Insert the other rows to we end up with a subset of the employee history table
    --with only rows that match the sbi_employee_id of the submitted row
         --DBMS_OUTPUT.PUT_LINE('Inserting into temp table...');
    open c_row;
    loop
    fetch c_row into r_row;
    exit when c_row%NOTFOUND;
    execute immediate 'INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
    VALUES(' || r_row.SBI_EMPLOYEE_ID || ',
    ''' || r_row.CURRENT_FLAG || ''',
    to_date(''' || to_char(r_row.EFFECTIVE_START, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''),
    to_date(''' || to_char(r_row.EFFECTIVE_END, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''))';
    end loop;
    close c_row;
    DBMS_OUTPUT.PUT_LINE('After inserts');
    -----Store queries to determine values for validation--------------------------
    v_sql_prev_eff_end := 'SELECT to_char(max(effective_end), ''dd-mon-yy'')
    FROM AGENT_SILO.AS_TEMP_VALIDATE
    where to_char(EFFECTIVE_END, ''dd-mon-yy'') != ''31-dec-99'' AND
    SBI_EMPLOYEE_ID = NEW_SBI_EMPLOYEE_ID';
    --Find the largest effective_end, besides the 9999 value
    execute immediate v_sql_prev_eff_end into v_prev_effective_end;
    DBMS_OUTPUT.PUT_LINE('The highest previous end date: ' || v_prev_effective_end);
    --...........Validation testing...........
    execute immediate 'DROP TABLE AGENT_SILO.AS_TEMP_VALIDATE'; --Drop temp table
    DBMS_OUTPUT.PUT_LINE('Validation Procedure Complete');
    COMMIT;
    status:='Success';
    EXCEPTION
    When Others Then
    ROLLBACK;
    Status := SQLERRM;
    END;
    Thanks a bunch for helping a noob out.

  • Swing button to insert row in displayed table records set

    Hi,
    I have been trying to insert custom row by pressing button in Swing form, this row should be displayed as last record in the records set fetched from table shown in the Swing form, can I have a help on this.
    cheers.

    Hi,
    the way you do this with ADF is to create an action binding for the ViewObject's CreateInsert operation. You do this in the pageDef file. Then from teh button, you use the panelBinding object to execute that method. Get access to the iterator binding and fill in the infromation you want to add. Then commit the change.
    If i find time I'll blog an example at orablogs.oracle.com/fnimphius
    Frank

  • Oracle Spatial - inserts/updates to geometry tables

    I am getting the following errors when inserting into an SDO_GEOMETRY object type:
    java.sql.SQLException: ORA-29877: failed in the execution of the ODCIINDEXUPDATE routine
    ORA-13000: dimension number is out of range
    ORA-06512: at "MDSYS.SDO_INDEX_METHOD", line 8
    ORA-06512: at "MDSYS.SDO_IDX", line 86
    ORA-06512: at "MDSYS.SDO_INDEX_METHOD", line 83
    ORA-06512: at line 1
    I have looked in the Oracle Spatial User Guide for 8i and have not been able to find much on the information above.
    Any help from inviduals with more expertise in this area would be great. If I need to provide more information please do indicate this as well
    Thanks,
    Faroon.

    Hi,
    The number of dimensions in the object being inserted may be
    out of the valid range ( 2 to 4).
    Or the diminfo in the user_sdo_geom_metadata for this
    layer has been changed the after the index is created.
    Check these two places first to make sure the dimensionality
    is in the valid range.
    The error is raised on index updated when the dimensionality
    of the object being updated is not in the valid range.
    siva

  • Doubt in internal table record count

    Hi,
    i have an internal table with 5 fields. Last field is flag. In my internal table lot many records are there. i want to count only the records with flag 'E'. How to count the total records with 'E'.
    Mohana

    Try like this,
    Data: c type i.
    Loop at itab into wa.
    if wa-flag = 'E'.
    c = c + 1.
    endif.
    Endloop.
    Write:/ 'Total records', c.
    OR
    LOOP AT itab WHERE flag = 'E'.
      c = c + 1.
    ENDLOOP.
    Edited by: Sap Fan on Apr 3, 2009 5:21 PM

  • Table Record Count

    In PL/SQL,
    for table ZXC
    and numeric varaible ZXC_Record_Count
    how would I determine the number of records in ZXC and pass that value to ZXC_Record_Count?
    or,
    what would be the syntax to get to some kind of property like ZXC.Count?
    TIA,
    Far Farley

    If you want the completely accurate answer, you'd need to do a COUNT(*), i.e.
    SELECT COUNT(*)
      INTO ZXC_Record_Count
      FROM zxcOf course, that can be rather slow. If an approximate count is acceptable and you're using the CBO and your statistics are reasonably accurate, you could do
    SELECT num_rows
      INTO ZXC_Record_Count
      FROM user_tables
    WHERE table_name = 'ZXC'That's more efficient, but less accurate.
    Justin

  • Problem with global temporary table in Oracle 10g

    Hi All,
    I face a peculiar problem in Oracle 10g with respect to Global temporary table.
    Have Oracle 10g version in Production and 11g version in UAT.
    Table_
    create global temporary table TT_TEMPGPSMANUAL
      Col_1    VARCHAR2(50),
      Col_2    VARCHAR2(500),
      Col_3    VARCHAR2(50),
      Col_4    VARCHAR2(50),
      Col_5    VARCHAR2(15),
      Col_6    VARCHAR2(20),
      Col_7    VARCHAR2(250),
      Col_8    VARCHAR2(20),
      Col_9    VARCHAR2(15),
      Col_10   VARCHAR2(20),
      Flag     NUMBER,
      Col_11   INTEGER,
      Col_12   VARCHAR2(50)
    on commit preserve rows;So this should preserve the rows inserted into this table until the session ends.
    Have a webpage in front-end where in turn, it opens another page (session is carried through) and a few rows will be inserted to this table from the webpage (through a function) on submit and the current page will be closed.
    From the parent page, if I open the sub-page data inserted in the temporary table are held and displayed (another function to fetch the values in the Global Temp table).
    The Problem in Oracle 10g (Production) is, this is not happening properly. When I close and open the sub-page, not every time I get the data stored i.e if I close and open the page 10 times, atelast 4 times the data is missed in the page (I am not getting values from temp table) randomly.
    But this does not happen in UAT (which has Oracle 11g installed) as I get the data in the webpage consistently. After passing UAT, when we rolled out to Prod, getting this issue which we are unable to get what could be the reason.
    It is very hard to debug using GTT dynamically in prod. It takes time to get Oracle 11g installed in Prod.
    Can anyone suggest?
    Regards
    Deep

    935195 wrote:
    Also, I am opening the sub-page from the parent page (through a hyperlink). Then in this case, Would session will be changed from parent to subpage? (I am not aware exactly and have the impression that, as the second page is a child, I guess it would take the same session).I'm not sure what "sub-page" or "parent page" means to you. If you're just linking from one page to another, "parent" and "child" don't really make sense since page A links to page B and B links to A quite frequently.
    Assuming that you have to log in to access the site, it is likely that the two pages share the same middle tier application session. It is unlikely that the middle tier would hold the database session from the first request open waiting to see if the user eventually requested the second page. It is theoretically possible that you could code your middle tier this way but it is extremely unlikely that you would want to do so for a variety of reasons. So, when you say "would [the] session ... be changed", it is likely that the application session would be the same for both calls but that the database session would be different.
    Justin

  • Where the tables will occur in oracle 10g

    hi,
    I am learning Oracle 10g.. i have created tables and stored some records in that table... but i can't find the storage location(folder) of that table. So, anyone expert in Oracle 10g, please help me to find this....

    Hi!
    Your tables are always stored in Tablespaces, if you omit the tablespace clause in your create table statement, they will go to your default tablespace.
    You can find this tablespace using
    select default_tablespace from dba_users where username='your username';
    using this tablespace name you can find out the datafiles of that tablespace using
    select file_name from dba_data_files where tablespace_name='the tablespace_name from above';
    Then you would know where your tables are stored.
    Regards,
    PP

Maybe you are looking for