How table statistics going to affect insert statements

I have 2 DB's.I have a process in both DB's which will load records in to tab1 using sql loader.Tab1 in DB1 is not analyzed since 2005 while tab1 in DB2 is recently analyzed.My SQL ldr process is slow in DB1 when compared to DB2.
I am wondering how sqlloader insert is goign to relate with statistics of table.Please suggest me
Thanks

Hi,
are You speaking about to identical instances, where the only difference are the statistics?
There are severa aspects that can impact, the instance configuration, the session configuration, the storage parameters, DB workload and so on.
Have You first checked what it is constant in both instances? Thios can be a good starting point..

Similar Messages

  • How to use table name as variable in insert statement

    Hi,
    I want to insert data from the cursor into the table and I want to submit table name as a variable. I tried the code below but it's not working. Any ideas how to solve this problem? Thx
    DECLARE
    v_new_table_name VARCHAR2(30) := 'test';
    --open cursor   
    CURSOR ACM IS
    SELECT *
    FROM DWH.CLI_DIMENSION@SLSPDW CLI
    WHERE where_clause
    FROM some_table;
    BEGIN
    FOR REC_ACM IN ACM LOOP
    EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM'; --table name as a variable in which the data from cursor will be inserted
    V_ROWCOUNT := V_ROWCOUNT + 1;
    IF MOD(V_ROWCOUNT, 100) = 0 THEN --this feature commits after 100 rows.
    COMMIT;
    END IF;
    END LOOP;
    COMMIT;
    DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
    END;

    Try this and let me know if it works. I have not tested it so I can not say for sure.
    DECLARE
      v_new_table_name VARCHAR2(30) := 'test';
      CURSOR ACM IS
        SELECT * FROM DWH.CLI_DIMENSION@SLSPDW CLI
                WHERE where_clause
                FROM some_table;
      BEGIN
      loop
       fetch ACM INTO REC_ACM
       exit when ACM%NOTFOUND;
       EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM';
       V_ROWCOUNT := V_ROWCOUNT + 1;
       IF MOD(V_ROWCOUNT, 100) = 0 THEN
        COMMIT;
       END IF;
      end loop;
      COMMIT;
      DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
      END;

  • How to get back fields from INSERT statement in batch mode(getGeneratedKeys

    Hi,
    I wanted to insert records to database and get back some fields.
    I create prepared statement:
    preparedStatement = connection.prepareStatement(sqlQuery, columnIndexes);
    then I set parameters.
    Following code works properly:
    preparedStatement.executeUpdate();
    generatedKeys = preparedStatement.getGeneratedKeys();
    if (generatedKeys.next()) {
    doSomething();
    But when I try to do this by batch I get exception:
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 22
         at oracle.jdbc.driver.T4CNumberAccessor.unmarshalOneRow(T4CNumberAccessor.java:190)
         at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:612)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
         at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:966)
         at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10644)
         at org.jetel.component.DBOutputTable.runInBatchMode(DBOutputTable.java:619)
    My "batch" code:
    for(...){
    setParameters(preparedStatement);
    preparedStatement.addBatch();
    preparedStatement.executeBatch();
    Isn't it a bug?
    Can I get back fields (eg. from last insert added to batch)?
    I hope somebody can help me.
    Agata

    This code works for me but only inserting one row. More than one causes an ArrayIndexOutOfBoundsException once sendBatch is called.

  • How to improve the performance of insert statement.

    Hi All,
    I have one procedure and it inserts 40 million records into one table. As my current method taking long time to accomplish the task, Is there any mechanism to improve the performance
    Thanks in Advance.

    > Thanks for pointing out my mistake Billy :)
    It is a common misconception it seems - that Oracle PQ is only useful for multi CPU platforms. I have seen it mentioned numerous times since the Oracle 7 OPS days in the mid 90's.
    > Edit: Could you please highlight which operations
    benefit from a multi-cpu machine?
    More CPUs increase the CPU capacity of the platform (and not speed). Allows it to run more processes.
    So very simplistically - on a single CPU box you find only sufficient CPU capacity (free CPU time) to run a parallel degree of 2 (i.e. 2 PQs). On a 4 CPU box, you may sufficient capacity for a degree of 10.
    But there are some catches here.
    Oracle PQ is specifically used for I/O sharing. Instead of a single process doing all the I/O, the I/O is shared amongst a bunch of PQ processes.
    The real bottle neck here is actually the size of the pipe to the disk.
    Simple example: You may have sufficient CPU capacity to run 20 PQs. But the I/O pipe will be seriously hammered as the pipe can only do a 1000 IOs/sec, and these 20 PQs are trying to push 10,000 IOs/sec.
    Another catch is that there are overheads when using SMP (symetrical multi processing). Again, very basically: as only a single CPU can for example access a specific piece of memory, two processes running on two different CPUs can cause "contention" when trying to access this memory (e.g. a typical piece of shared memory).
    So having two related processes running on two different CPUs can be in fact slower than having both related processes running on the same CPU.
    This is quite noticeable on Windows NT/2000/XP kernel for example. Windows will load the 1st CPU close to capacity, before spilling across to the 2nd CPU. It is the norm to see the 1st CPU with high usage and the 2nd CPU running almost idle. (something that seems to have PC gamers confused in recent times when using "high-end" dual core machines and not understanding why the 2nd CPU does not seem to be used)
    Bottom line. Multi-CPU platforms provide more processing capacity for running PQ than a single CPU platform. But a single CPU is capable of running PQ if there is capacity (which is often the case).

  • INSERT Statement behind a FORM on a TABLE with REPORT

    When I create a form on a table with report, I'm sure an INSERT STATEMENT is genereated in the background somewhere. How can I see this insert statement or how can I get to this INSERT statement? If I can see it, would I be able to modify this INSERT statement?
    Please use simple terms.
    Thanks.

    Roel
    At first, i was just curious to see where that insert statement is and how it looks like.
    Later, I really wanted to see it because I wanted to know how it looks like whne I try to insert a one to many relationship record. Don't know if I'm being too clear on this.
    Lets say table A and B have a 1-to-many relationship. When I want to insert records into both A and B, how does the insert work? Maybe if I get an answer to this question, I may understand how the inserts are done on a 1 to many relationship data insert.
    Thanks.

  • INSERT statement in Java and MS Access

    Hi all,
    can anyone please tell me how to insert data to an MS Access table using JSP i tried INSERT statement of java but it is getting errors saying INSERT statement is wrong. I have no idea about MS access insert statement. i am totally tired of this. Please someone help me.

    Hello,
    MS Sql can cause problems where it goes off standard, however I dont think insert is any different.
    INSERT INTO table_name (column1, column2) VALUES (variable1, variable2)
    Make sure your table and column names are exactly right, Java is case sensitive, so make sure the case is correct also.
    The other common error is if you have a required field in the database that is not populated by your program, so, if for instance there was a column3 in the table for the above example, which was a required field, the sql would fail as there is no data being entered for column3.

  • Insert Statement taking longer time

    Hi,
    One of my insert statement inside the procedure is taking more than 10secs to complete.
    Scenario:
    1. Having three tables e.g invoice table - invoice header, invoice Item and invoice attribute
    2. These tables are loaded with data in the above specified order and they are not commited till all the data for an invoice gets inserted sucessfully.
    e.g
    a. Invoice header gets inserted first(one row)
    b. Invoice Item second(will be in a loop with more than one row)
    c. For every Invoice item an invoice attribute will be inserted
    (Invoice Attribute has a FK column with a PK column in invoice item table column)
    The problem is while inserting data into InvoiceAttribute it takes more than 10sec, IF the FK(mentioned above) is disabled insert statement is running fine.
    note: Invoice Item table has 8.4million records
    My assumption :
    while inserting into Invoice attribute table the insert statement validated the FK with the invoice item table, since the new Inovice item id(PK column in invoice Item table) is not commited the insert statement takes time to validate the FK against (8.4million records)......
    Please suggest me a solution.....................
    Thanks in advance
    NaveenPeri

    I'll try with a blind shot : The FK is likely missing an index, thus performing full table scan on invoice attribute each time you perform an insert on the invoice attribute table.
    By default an FK doesn't have an index. You must create one manually.
    If this turns out to be a missfire then please post a plan with statistics for the attribute insertion.
    Message was edited by:
    76°®

  • Insert statement taking time on oracle 10g

    Hi,
    My procedure taking time in following statement while database upgrading from oracle 9i to oracle 10g.
    I m using oracle version 10.2.0.4.0.
    cust_item is matiralize view in procedure and it is refreshing in the procedure
    Index is dropping before inserting data into cust_item_tbl TABLE and after inserting data index is created.
    There are almost 6 lac records into MV which are going to insert into TABLE.
    In 9i below insert statement is taking 1 hr time to insert while in 10g it is taking 2.30 hrs.
    EXECUTE IMMEDIATE 'ALTER SESSION ENABLE PARALLEL QUERY';
    EXECUTE IMMEDIATE 'ALTER SESSION ENABLE PARALLEL DML';
    INSERT INTO /*+ APPEND PARALLEL */ cust_item_tbl  NOLOGGING
             (SELECT /*+ PARALLEL */
                     ctry_code, co_code, srce_loc_nbr, srce_loc_type_code,
                     cust_nbr, item_nbr, lu_eff_dt,
                     0, 0, 0, lu_end_dt,
                     bus_seg_code, 0, rt_nbr, 0, '', 0, '', SYSDATE, '', SYSDATE,
                     '', 0, ' ',
                                   case
                                 when cust_nbr in (select distinct cust_nbr from aml.log_t where CTRY_CODE = p_country_code and co_code = p_company_code)
                                 THEN
                                         case
                                            when trunc(sysdate) NOT BETWEEN trunc(lu_eff_dt) AND trunc(lu_end_dt)
                                            then NVL((select cases_per_pallet from cust_item c where c.ctry_code = a.ctry_code and c.co_code = a.co_code
                                                          and c.cust_nbr = a.cust_nbr and c.GTIN_CO_PREFX = a.GTIN_CO_PREFX and c.GTIN_ITEM_REF_NBR = a.GTIN_ITEM_REF_NBR
                                                          and c.GTIN_CK_DIGIT = a.GTIN_CK_DIGIT and trunc(sysdate) BETWEEN trunc(c.lu_eff_dt) AND trunc(c.lu_end_dt) and rownum = 1),
                                                          a.cases_per_pallet)
                                      else cases_per_pallet
                                  end
                          else cases_per_pallet
                     END cases_per_pallet,
                     cases_per_layer
                FROM cust_item a
               WHERE a.ctry_code = p_country_code ----varible passing by procedure
                 AND a.co_code = p_company_code   ----varible passing by procedure
                 AND a.ROWID =
                        (SELECT MAX (b.ROWID)
                           FROM cust_item b
                          WHERE b.ctry_code = a.ctry_code
                            AND b.co_code = a.co_code
                            AND b.ctry_code = p_country_code ----varible passing by procedure
                            AND b.co_code = p_company_code   ----varible passing by procedure
                            AND b.srce_loc_nbr = a.srce_loc_nbr
                            AND b.srce_loc_type_code = a.srce_loc_type_code
                            AND b.cust_nbr = a.cust_nbr
                            AND b.item_nbr = a.item_nbr
                            AND b.lu_eff_dt = a.lu_eff_dt));explain plan of oracle 10g
    Plan
    INSERT STATEMENT  CHOOSECost: 133,310  Bytes: 248  Cardinality: 1                      
         5 FILTER                 
              4 HASH GROUP BY  Cost: 133,310  Bytes: 248  Cardinality: 1            
                   3 HASH JOIN  Cost: 132,424  Bytes: 1,273,090,640  Cardinality: 5,133,430       
                        1 INDEX FAST FULL SCAN INDEX MFIPROCESS.INDX_TEMP_CUST_AUTH_PERF_MV Cost: 10,026  Bytes: 554,410,440  Cardinality: 5,133,430 
                        2 MAT_VIEW ACCESS FULL MAT_VIEW MFIPROCESS.TEMP_CUST_AUTH_PERF_MV Cost: 24,570  Bytes: 718,680,200  Cardinality: 5,133,430  can you please look into the issue?
    Thanks.

    According to the execution plan you posted parallelism is not taking place - no parallel operations listed
    Check the hint syntax. In particular, "PARALLEL" does not look right.
    Running queries in parallel can either help performance, hurt performance, or do nothing for performance. In your case a parallel index scan on MFIPROCESS.INDX_TEMP_CUST_AUTH_PERF_MV using the PARALLEL_INDEX hint and the PARALLEL hint specifying the table for MAT_VIEW MFIPROCESS.TEMP_CUST_AUTH_PERF_MV Cost might help, something like (untested)
    select /*+ PARALLEL_INDEX(INDX_TEMP_CST_AUTH_PERF_MV) PARALLEL(TEMP_CUST_AUTHPERF_MV) */Is query rewrite causing the MVs to be read? If so hinting the query will be tricky

  • Insert statement with timezone asking for parameter

    I have an insert statement in a file.
    When the whole file is executed it inserts around 300 rows in to table.
    One of the insert statement is failing. This insert statement inserts a query into column of a table.
    It is as following
    Insert into hr.TABLE_PATH
    (PATH, TABLE_OWNER_NAME, TABLE_NAME, PATH_NAME, TABLE_ACCESS_PATH_DESC, TABLE_PATH_SQL_TXT, PROCESS_CODE, DELETE_IND, ACCESS_ID)
    Values
    (290, HR, EMPLOYEES, 'Reconc', 'XYZ', 'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )', 'N ', 'N', 2);
    The problem is with this piece of insert:
    TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp
    : --> is being considered as parameter.
    Where as the whole sql thing needs to get inserted into the table.

    If you are inserting a string, then any quotes inside the string should be replaced with two single quotes,
    try this,
    INSERT INTO hr.TABLE_PATH (PATH,
                               TABLE_OWNER_NAME,
                               TABLE_NAME,
                               PATH_NAME,
                               TABLE_ACCESS_PATH_DESC,
                               TABLE_PATH_SQL_TXT,
                               PROCESS_CODE,
                               DELETE_IND,
                               ACCESS_ID)
    VALUES (
             290,
             HR,
             EMPLOYEES,
             'Reconc',
             'XYZ',
             'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )',
             'N ',
             'N',
             2
           );Note the
    TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp First off, How are you inserting the data? using sqlldr or utl_file?
    If you are inseting using a script from Sqlplus
    use
    SET DEFINE OFFjust to make sure nothing is treated as a parameter.
    G.
    Edited by: Ganesh Srivatsav on Apr 6, 2011 5:20 PM

  • Insert statement in when-checkbox-checked trigger doesn't work

    in a when-checkbox-checked trigger, I wrote the follwing code :
    IF :sunday = 'Y' THEN
    msg_alert('Y','I',false);
    pkg_var.v_day_count := pkg_var.v_day_count + 1;
    msg_alert('1','I',false);
    :schtm_skmk.day_id := '1';
    msg_alert('2 ',I',false);
    INSERT INTO schtm      
    (ROUTE_ID, DAY_ID, FLIGHT_ID)
    VALUES
    (:schmf.ROUTE_ID, :schtm_skmk.day_id, 1);
    COMMIT;
    msg_alert('end insert schtm','I',false);
    END IF;     
    if the checkbox is checked, I assigned value '1' to day_id. Then, I want to insert a row into table SCHTM. But, the insert statement fail. The msg_alert '2' pop up. The msg_alert 'end insert schtm' does not pop up, meaning the insert statement fail. It also fail after I replace the insert statement with the exact value of the item. But if I execute this statement in SQL plus, it insert a row into the database.
    What is strange here is it did work before, I successfully insert 2 rows into database. But when I test it again just a while later, it never work anymore.
    Please help.
    Thanks,
    Shu Wen

    It seems that you have missed ELSE. By the way there is only one INSERT ...

  • How to get the table name and bind columns names in an INSERT statement ?

    I have an INSERT statement with input parameters (for example
    INSERT INTO my_table VALUES (:a, :a, :a)) and I want to know
    without parsing the statement which is the name of table to
    insert to and the corresponding columns.
    This is needed to generate the SELECT FOR UPDATE statement to
    refetch a BLOB before actually writing to it. The code does not
    know in advance the schema (generic code).
    Thanks in advance,
    Joseph Canedo

    Once you have prepared your statement, you can execute the
    statement with the OCI_DESCRIBE_ONLY mode before binding any
    columns. Then you can use OCIParamGet to find out about each
    column (column index is 1-based). You should get OCI_NO_DATA or
    ORA-24334 if there are no more columns in the statement. Note
    that the parameter descriptor from OCIParamGet is
    allocated/freed internally by OCI; you do not need to manage it
    explicitly. The parameter descriptor is passed to OCIAttrGet in
    order to obtain for instance the maximum size of data in the
    column OCI_ATTR_DATA_SIZE. You can also get the column name in
    this way, although I do not remember the #define off the top of
    my head. Getting the table name appears to be much more
    difficult; I have never had to do that yet. Good luck. -Ralph

  • How to tune the Insert statement?

    Hi ,
    I am using 10.2.0.4.0 version of oracle.
         i am having one insert statement , which comes almost all the time in the TOP of my AWR elapsed time section.
         And its somewhat similar to as below.
    Query:
    INSERT INTO a (InvoicePK, CheckPK)
    SELECT DISTINCT ih.InvoicePK, cd.CheckPK
    FROM at,
    cd,
    ih,
    rd
    WHERE at.AttachmentPK = :1
    AND cd.CheckPK = at.CheckPK
    AND at.AttachmentPK = rd.AttachPK
    AND ih.PAYPK = cd.PAYEEPAYPK
    AND ih.PayerNS = cd.PayerNS
    AND ih.PayerPayId = cd.PayerPayId
    AND ih.UpperInvoiceNum = rd.UPPERINVNUM
    AND ih.InvoiceStatusCD NOT IN ('REJ', 'DNY');
    Below is the plan for the 'Select ' statement i.e. used in the insert statement.
    Execution Plan:
    Plan hash value: 2232002808
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 1 | 193 | 9 (23)| 00:00:01 | | |
    | 1 | HASH UNIQUE | | 1 | 193 | 9 (23)| 00:00:01 | | |
    |* 2 | HASH JOIN | | 1 | 193 | 8 (13)| 00:00:01 | | |
    | 3 | NESTED LOOPS | | 10 | 1740 | 4 (0)| 00:00:01 | | |
    | 4 | NESTED LOOPS | | 1 | 85 | 3 (0)| 00:00:01 | | |
    | 5 | TABLE ACCESS BY INDEX ROWID | at | 1 | 16 | 2 (0)| 00:00:01 | | |
    |* 6 | INDEX UNIQUE SCAN | atpk1 | 1 | | 1 (0)| 00:00:01 | | |
    | 7 | TABLE ACCESS BY INDEX ROWID | cd | 7359K| 484M| 1 (0)| 00:00:01 | | |
    |* 8 | INDEX UNIQUE SCAN | cdpk1 | 1 | | 1 (0)| 00:00:01 | | |
    |* 9 | TABLE ACCESS BY GLOBAL INDEX ROWID| ih | 10 | 890 | 2 (0)| 00:00:01 | ROWID | ROWID |
    |* 10 | INDEX RANGE SCAN | IH_PAYPK_PAYERNS_PAYID | 5 | | 1 (0)| 00:00:01 | | |
    | 11 | TABLE ACCESS BY INDEX ROWID | rd | 9 | 171 | 3 (0)| 00:00:01 | | |
    |* 12 | INDEX RANGE SCAN | IDX_rd | 9 | | 2 (0)| 00:00:01 | | |
    Predicate Information (identified by operation id):
    2 - access("IH"."UPPERINVOICENUM"="RD"."UPPERINVNUM")
    6 - access("AT"."ATTACHMENTPK"=7794833983)
    8 - access("CD"."CHECKPK"="AT"."CHECKPK")
    9 - filter("IH"."INVOICESTATUSCD"<>'REJ' AND "IH"."INVOICESTATUSCD"<>'DNY')
    10 - access("IH"."PAYPK"="CD"."PAYEEPAYPK" AND "IH"."PAYERNS"="CD"."PAYERNS" AND "IH"."PAYERPAYID"="CD"."PAYERPAYID")
    12 - access("RD"."ATTACHPK"=7794833983)
    Statistics
    1 recursive calls
    0 db block gets
    71 consistent gets
    0 physical reads
    0 redo size
    316 bytes sent via SQL*Net to client
    240 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    3 rows processed
    The 'select' Statement executes with in seconds resulting 3 distinct records, but the insert statement takes ~20sec(Elaps time per execution
    as shown in AWR report) for one time execution, so what must be the reason , and how should i proceed to resolve this performance issue?

    You can do as follows:
    - Enable trace
    - execute the insert statement
    - use tkprof (and put the results here) to see where's its taking long
    Also, while insert is being executed, what are the wait events you see ?
    I dont think there is problem with plan.

  • Generate Insert Statement Script to Extract Data from Table in Oracle 7i

    Hi all, I have an old Oracle legacy system that is running for over 15 years.Every now and then we need to extract data from this table@ ORacle 7i to be imported back to Oracle 10G.
    My thoughts are to create a script of Insert statements in oracle 7 and that to be deployed back to Oracle 10G.
    I found this scripts in Google and not sure how exactly this works.Any explanation on thsi scripts , would be greatly appreciated.I find this scripst may help to generate a set of insert statements from that table to the latest table at 10G.
    <pre>
    -- Step 1: Create this procedure:
    create or replace Function ExtractData(v_table_name varchar2) return varchar2 As
    b_found boolean:=false;
    v_tempa varchar2(8000);
    v_tempb varchar2(8000);
    v_tempc varchar2(255);
    begin
    for tab_rec in (select table_name from user_tables where table_name=upper(v_table_name))
    loop
    b_found:=true;
    v_tempa:='select ''insert into '||tab_rec.table_name||' (';
    for col_rec in (select * from user_tab_columns
    where
    table_name=tab_rec.table_name
    order by
    column_id)
    loop
    if col_rec.column_id=1 then
    v_tempa:=v_tempa||'''||chr(10)||''';
    else
    v_tempa:=v_tempa||',''||chr(10)||''';
    v_tempb:=v_tempb||',''||chr(10)||''';
    end if;
    v_tempa:=v_tempa||col_rec.column_name;
    if instr(col_rec.data_type,'CHAR') > 0 then
    v_tempc:='''''''''||'||col_rec.column_name||'||''''''''';
    elsif instr(col_rec.data_type,'DATE') > 0 then
    v_tempc:='''to_date(''''''||to_char('||col_rec.column_name||',''mm/dd/yyyy hh24:mi'')||'''''',''''mm/dd/yyyy hh24:mi'''')''';
    else
    v_tempc:=col_rec.column_name;
    end if;
    v_tempb:=v_tempb||'''||decode('||col_rec.column_name||',Null,''Null'','||v_tempc||')||''';
    end loop;
    v_tempa:=v_tempa||') values ('||v_tempb||');'' from '||tab_rec.table_name||';';
    end loop;
    if Not b_found then
    v_tempa:='-- Table '||v_table_name||' not found';
    else
    v_tempa:=v_tempa||chr(10)||'select ''-- commit;'' from dual;';
    end if;
    return v_tempa;
    end;
    show errors
    -- STEP 2: Run the following code to extract the data.
    set head off
    set pages 0
    set trims on
    set lines 2000
    set feed off
    set echo off
    var retline varchar2(4000)
    spool c:\t1.sql
    select 'set echo off' from dual;
    select 'spool c:\recreatedata.sql' from dual;
    select 'select ''-- This data was extracted on ''||to_char(sysdate,''mm/dd/yyyy hh24:mi'') from dual;' from dual;
    -- Repeat the following two lines as many times as tables you want to extract
    exec :retline:=ExtractData('dept');
    print :retline;
    exec :retline:=ExtractData('emp');
    print :retline;
    select 'spool off' from dual;
    spool off
    @c:\t1
    -- STEP3: Run the spooled output c:\recreatedata.sql to recreate data.
    Source:http://www.idevelopment.info/data/Oracle/DBA_tips/PL_SQL/PLSQL_5.shtml
    </pre>

    Thanks Justin.
    I get what you are saying,i really wanted to see the output of the codes, because the furtherst i could get from that code is
    SELECT EXTRACTDATA('MYTABLE') FROM MYTABLE;
    and it generated this:
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    "select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
    select '-- commit;' from dual;"
    I was expecting a string of
    insert into mytable values (19/1/2009,1,1);
    insert into mytable values (19/10/2008,5,10);
    Thanks for the explanation .

  • How to use record type for inserting data into a table

    I've read through the web the following tip:
    "When working with a large number of columns, using variables of type RECORD is a better approach. With this approach, you do not have to list anything in the INSERT statement, because you are inserting a variable into the table that is defined as a row from the same table."
    I usually define a variable as
    r_mytable     mytable%ROWTYPE;
    and inside my procedure I'll set the fields I need as
    r_mytable.field1 := 1;
    r_mytable.field3 := 7;
    and then I perform the insert as
    insert into mytable
    (field1,
    field3)
    values
    (r_mytable.field1,
    r_mytable.field3);
    According to the tip I've copied above, how can I use the TYPE RECORD of pl/sql for achieving the same result but perhaps in a smarter way?
    Thanks in advance!

    Hi,
    Are you looking for this?
    SQL> create table table1 (id number, descr varchar2(30));
    Table created
    SQL>
    SQL> DECLARE
      2   my_rec table1%rowtype;
      3  BEGIN
      4   my_rec.id := 1;
      5   my_rec.descr := 'TEST';
      6   insert into table1 values my_rec;
      7  END;
      8  /
    PL/SQL procedure successfully completed
    SQL> select * from table1;
       ID DESCR
        1 TESTWorks with UPDATE too :
    SQL> DECLARE
      2   my_rec table1%rowtype;
      3  BEGIN
      4   my_rec.id := 2;
      5   my_rec.descr := 'TEST2';
      6   update table1 set row = my_rec where id = 1;
      7  END;
      8  /
    PL/SQL procedure successfully completed
    SQL> select * from table1;
       ID DESCR
        2 TEST2

  • Using 1million insert statement to create a table

    Dear Expert;
    Lets say someone sent you about 2 million insert statements and you want to use them to insert into a table or create a new table...How do you go about doing so...
    because I tried just highlighting all the insert statement and executing them, however that didnt work in pl/sql developer, it was crashing everytime I did so
    The other way might be to create a loop for them and inserting about 10,000 at a time...but is there a faster way to do it...
    All help is appreciated it..

    user13328581 wrote:
    Dear Expert;
    Lets say someone sent you about 2 million insert statements and you want to use them to insert into a table or create a new table...How do you go about doing so...
    because I tried just highlighting all the insert statement and executing them, however that didnt work in pl/sql developer, it was crashing everytime I did soDo it in SQL*PLUS. It can handle such large files.
    And let it run at night so that other users are not influenced that much by your session.
    You might want to add very few commits somewhere in between. However in case something breaks you then need to know which insert was still executed and which one one.

Maybe you are looking for