Truncate Table before Insert--Performance

HI All,
This post is in focus of special requirement where a table is truncated before inserting records in the table.
Now, when a table is truncated the High Water Mark(HWK) is reset to lowest memory allocated for table in tablespace. After this, would insert with append can boost the performance of the insert query?
In simple insert query, the oracle engine consults the free list to look for free spaces.
But in insert with apppend, the engine starts above the HWM. And the argument is when truncate has been executes on table, would the freelist be used in simple insert.
I just need to know if there are any benefits of using append insert on truncated table or simple insert would be same in term of performance with respect to insert with append.
Regards
Nits

Hi,
if you don't need the data truncate the table. There is no negativ impact whether you are using an conventional path or a direct path insert.
If you use append less redo is written for the table if the table is in NOLOGGING mode, but redo is written for all indexes. I would recommand to create a full backup after that (if needed), because your table will not be recoverable after that (no REDO Information).
Dim

Similar Messages

  • Truncate field before insert

    Suppose I have the following:
    table: mytable
    field: username (VARCHAR2(35))
    field: zip (VARCHAR2(5))
    I am importing data from an excel file with columns username and zip. A couple of the usernames contain more than 35 characters, and some of the zipcodes are in the xxxxx-xxxx format, thus containing more than 5 characters.
    I attempted to write a before insert trigger to truncate the data before they are inserted. For any username that is above 35 characters from the excel file, just truncate the username to the first 35 characters. Similarly, for any zip code that is above 5 characters, just truncate the zip to the first 5 characters.
    The trigger for the zip codes:
    CREATE OR REPLACE
    TRIGGER trigger_zipc
      BEFORE INSERT
      ON mytable
      FOR EACH ROW
    BEGIN
      SELECT substr(:new.zip, 1, 5)
      INTO :new.zip
      from dual;
    END;
    However, I get the error: ORA-12899: value too large for column
    I've read on other forums that this is what happens, and that a possible work around is to use INSERT INSTEAD??
    Can anyone give me a solution or point me in the right direction?

    Can anyone give me a solution or point me in the right direction?
    Sure - the 'right direction' is to mark this thread ANSWERED and repost your question in the Sql and Pl/Sql forum:
    PL/SQL
    This forum is ONLY for Sql Developer questions and your question doesn't appear to have anything to do with that tool.
    As the exception says the value is too large for the column. Your code that tries to trim the value will NEVER be executed because the exception occurs BEFORE it ever gets that far.
    The buffer that Oracle creates to hold that :NEW value is too small to hold the value you try to insert - that is why you get the exception.
    You can NOT use a trigger to perform validations such as those since the data will NEVER make it into the buffer the trigger uses.before it ever executes your code.

  • Should I create table before insert xml files

    Hi,,,
    I am developing a application that insert various xml files
    into oracle8i dbms..
    So, I am studying Oracle XML SQL Utility and I understood that
    I should create appropriate tables suit for the XML files..
    (tag <--> table column name...) before insert them to the dbms.
    But In my project, the xml file is not fixed.
    And new XML files (new tag name, new DTD required) can be
    generated by the end user.
    Is there any solution??? create table suit for xml
    automatically..
    And...
    How can I create table to insert the following xml file..
    <univ>
    <college name="engineering">
    <department name="electronic">
    <student id="11">
    <math> 100 </math>
    <english> 90 </english>
    </student>
    </department>
    </college>
    <college name="law">
    <department name="law">
    <student id="55">
    <math> 90 </math>
    <english> 100 </english>
    </student>
    </department>
    </college>
    </univ>
    null

    Hi,
    One more thing is that, you can use XSLT to transform any
    document that you get into a canonical representation that u can
    then use to put into the database.
    For example, if the user gave,
    <univ>
    <college name="eng">
    <...>
    </college>
    </univ>
    you can then use XSLT to transform it into all-element form,
    such as,
    <univ>
    <college>
    <name>engineering</name>
    </college>
    </univ>
    and use OracleXMLSave to put it into the database. Also if you
    have structured XML elements you can map them nicely into object
    types in Oracle 8.
    Regarding creating the table, for the exampe that you showed,
    you can create an object type column for storing it,example,
    CREATE TYPE college_type AS OBJECT
    name VARCHAR2(50),
    dept department_type,
    CREATE TYPE department_type AS OBJECT
    name VARCHAR2(40),
    CREATE TABLE univ_tab ( college college_type);
    You could have also created object views over multiple
    relational tables and achieved the same.
    Thx
    The OracleXML team.
    Oracle XML Team wrote:
    : Instead of using attributes to store your data, use elements.
    : For example:
    : <univ>
    : <college>
    : <collname>engineering</collname>
    : <department>
    : <deptname>electronic</deptname>
    : <student>
    : <id>11</id>
    : <math>100</math>
    : <english>90</english>
    : </student>
    : </college>
    : </univ>
    : Oracle XML Team
    : http://technet.oracle.com
    : Oracle Technology Network
    : Chong, Ho-chul (guest) wrote:
    : : Hi,,,
    : : I am developing a application that insert various xml files
    : : into oracle8i dbms..
    : : So, I am studying Oracle XML SQL Utility and I understood
    : that
    : : I should create appropriate tables suit for the XML files..
    : : (tag <--> table column name...) before insert them to the
    dbms.
    : : But In my project, the xml file is not fixed.
    : : And new XML files (new tag name, new DTD required) can be
    : : generated by the end user.
    : : Is there any solution??? create table suit for xml
    : : automatically..
    : : And...
    : : How can I create table to insert the following xml file..
    : : <univ>
    : : <college name="engineering">
    : : <department name="electronic">
    : : <student id="11">
    : : <math> 100 </math>
    : : <english> 90 </english>
    : : </student>
    : : </department>
    : : </college>
    : : <college name="law">
    : : <department name="law">
    : : <student id="55">
    : : <math> 90 </math>
    : : <english> 100 </english>
    : : </student>
    : : </department>
    : : </college>
    : : </univ>
    Oracle Technology Network
    http://technet.oracle.com
    null

  • Trigger that checks if value exists in another table before insert

    Hi,
    Can any one help me with the correct code.
    I am trying to write a trigger that checks if the new value (:new.T1) does not exist in another table (T2) before entering it (in T1).
    Create or replace trigger T1
    BEFORE
    insert on T1
    for each row
    Declare
    x Number;
    begin
    SELECT Count (*) INTO x
    From T2 WHERE T2.Col1 = :new.T1;
    IF (x > 1 or x = 1) Then
    DBMS_OUTPUT.PUT_LINE('This value has been used before try another one.');
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    INSERT INTO T2 (Col1) values (:new.T1);
    WHEN TOO_MANY_ROWS THEN
    DBMS_OUTPUT.PUT_LINE('This value has been used before try another one.');
    end;

    I think this question is suitable for the SQL and PL/SQL forum.

  • Should i drop schema or truncate tables before importing?

    I have exported a dump of the whole schema form oracle database. I need to import this to another database with a different schema name but same tables. The only thing i am doing is this to bring data consistent with the other database.
    Now Do i need to drop schema or do anything like that to avoid and redundancy or i can just go ahead and do the import? Please let me know how to do it. I would prefer not deleted any tables but truncate all the data if needed from about all 200 tables.
    Thanks

    For the places in your application where a Sequence is used to insert or set values in some tables, note that the sequence's current value may have been incremented if it has been used since the last import. If your truncate and re-import the tables, the tables may have the older (lower) values but the current sequence may be higher.
    You would then have to "reset" the sequence best by dropping and recreating it.

  • How to insert master table before insert detail table

    Hi all,
    There are two Entity Objects, one is EntityA(attribute1, attribute2....), one is EntityB(attribute1,..), attribute1 comes from EntityA and is primary key.
    I create a View Object named AView, it contain all the properties of EntityA and EntityB, i create a creation page also. when a user click the save button, i want to save them together.
    Please tell me how to do it?
    Thank you very much

    Hi , its simple !
    Just create two Form master detail based of EntityA and EntityB Manually. Make sure first Entity objects has foreign key constraints. If not have please create a VL(View Link) by referring same reference key.
    Then add entry forms based on VO of EntityA and EntityB .
    Regards.

  • Problem with truncate table in procedure ora -00054

    hi do anybody know where is mistake ???
    the procedure has problem with truncate table
    ora - 00054: resource busy and acquire with NOWAIT specified
    ora - 06512 at "POVAPSYS.HMAN_P_REFRESH", line 6
    ora - 06512 at "POVAPSYS.POVAPSYS", line 6
    ora - 06512 at line 1
    this is my procedure....
    AS
    BEGIN
    execute immediate 'TRUNCATE TABLE hman_t_max';
    INSERT INTO hman_t_max SELECT * FROM hman_v_max;
    COMMIT;
    END;

    2.MAKE SURE THAT OTHER THAN YOU ANYBODY IS TRYING TO
    COMPILE AND RUN THE PROCEDUREShould he make sure that anybody is running the procedure?
    3.MAKE SURE THAT ANY PARALLEL QUERY IS RUNNING IN THE
    SERVER SIDE,THATS KEEPS THE RESOURCE BUSYShould he make sure any parallel query is running in the server side to keep the resource busy?
    Gita,
    I COULDN'T RESIST HAVING ONE SUGGESTION FOR YOU. Please look at the impact of your English in the reply before posting. Check if that sends reverse message!
    Cheers
    Sarma.

  • Why should we create index on  the table after inserting data ?

    Please tell me the Reason, why should we create index on the table after inserting data .
    while we can also create index on the table before insertion of the data.

    The choice depends on a number of factors, the main being how many rows are going to be inserted in the table as a percentage of the existing rows, or the percentage growth.
    Creating index after a table has been populated works better when the tables are large or the inserts are large for the following reasons
    1. The sort and creation of index is more efficient when done in batch and written in bulk. So works faster.
    2. When the index is being written blocks get acquired as more data gets written. So, when a large number of rows get inserted in a table that already has an index , the index data blocks start splitting / chaining. This increases the "depth" of the inverted b-tree makes and that makes the index less efficient on I/O. Creating index after data has been inserted allows Orale to create optical block distribution/ reduce splitting / chaining
    3. If an index exists then it too is routed through the undo / redo processes. Thats an overhead which is avoided when you create index after populating the table.
    Regards

  • Checking table columns and data type before inserting

    I have some data coming from different sources and want to insert the data from those files into multiple tables.
    Before inserting the data I like to perform a check on data type, length, null etc so that I can avoid errors at the time of insert. If there is any problem with the data then I do not want to perform the insert and report the problems.
    Thanks

    If you have 10gR2 (10.2.0.4) you could use DML_ERROR_LOGGING.
    Read about it here, see the examples: http://tkyte.blogspot.com/2005/07/how-cool-is-this.html
    In short: it avoids errors during your transactions, afterwards you know which records failed and why.
    It's more or less the same functionality:
    your goal:
    check before transactions and avoid the insert of 'bad' records. (extra code, extra maintenance, more chance of bugs)
    dml_err_logging:
    insert 'bad' records during transaction automatically into a dedicated error table including error message.
    Edited by: hoek on Mar 24, 2009 6:56 PM

  • How to delete the Table Contents before inserting records into SQL table ?

    Hello Experts,
            I have a scenario where in I have to Pick up some records from SAP RFC & insert into SQL table.
            i know how to do this scenario but the proble with this is before inserting we first have to ZAP the SQL table & insert a new records. One more twist is The Triggering is happening from SAP side with Sender RFC. If this would have been from SQL Side i could have written a Stored Procedure/ Trigger & could have called this before the SENDER JDBC communciation channel picks up the Triggering event from SQL side.
    So how to do this scenarioin XI, First deleting all the Records of SQL table & then inserting the new reocrds. without using the BPM.
    Regards,
    Umesh

    hi umesh,
    you can achieve this by writing SQL query in message mapping level..
    refer this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/b0/676b3c255b1475e10000000a114084/frameset.htm
    regards.

  • Delete all data of a table in Oracle before insert operation in BizTalk.

    Hi,
    I need to delete all the data of a table from Oracle before insert data into it from BizTalk. I can't create stored procedure on the oracle table or how to create a xml of the delete schema of the oracle table in the BizTalk with filter node has a blank
    value because i need to delete all the data of the table so that i will send this xml as delete operation.
    Thanks in advance.
    Regards,
    Gyan

    You need to create two schemas: One for deleting all rows and one for inserting.
    Then combine these Schemas into one and use the "CompositeOperation" SOAP Action Header.
    Something like the below (a SQL Example, so the Schemas needs to be replaced by WCF-Oracle syntax)
    <Request xmlns="http://CompositeTest.CompositeSchema">
    <Delete xmlns="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/Employee">
    <Rows>
    <Employee xmlns="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo">
    </Employee>
    </Rows>
    </Delete>
    <Insert xmlns="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/Employee">
    <Rows>
    <Employee xmlns="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo">
    <Name>John</Name>
    <Designation>Manager</Designation>
    <Salary>100000</Salary>
    </Employee>
    </Rows>
    </Insert>
    </Request>
    Morten la Cour

  • Free Connections to a table before truncate

    Hi All,
    I need to kill all connections to table before truncating table in production environment.Is there any script for the same?
    Regards
    Rahul

    You don't really have a connection to a table, but processes take out locks on rows in the table as they access the rows. Or on table if they scan many rows.
    It would be possible to query sys.dm_tran_locks to get the processes that hold locks, but you cannot really prevent new processes to come in.
    A more lazy method is to issue your "TRUNCATE TABLE" in one query window, and then run sp_who in another. You process will be reported as blocked by other process, so you kill that process. Then you run sp_who again, kill that guy and so on.
    Then again, killing processes in a production environment? It's not entirely appetising.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Child node insert performance

    (Oracle Database 11g 11.1.0.6.0)
    I just ran a test to continually insert child XML nodes into an XML table and found performance slow. As the documentation states, the reason appears to be because the entire XML is being read into memory each time as a DOM before the insert.
    My question is whether there is a higher performing means of performing child node inserts?
    The test is as follows:
    i)     Create a non-schema based XML type table:
                        CREATE TABLE myTable1 (
                             id NUMBER,
                             XML_COLUMN XMLType
                        XMLTYPE COLUMN xml_document store as binary xml
    ii)     The table is initialized with one row of data:
         0, XMLTYPE('<trace-envelope>
                   <metadata>
                        <pid>12345</pid>
                        <date>2008-05-30</date>
                   </metadata>
              </trace-envelope>')
    iii)     Insert/append successive XML data using the following statement:
         UPDATE MyTable1 SET XML_COLUMN = APPENDCHILDXML(XML_COLUMN," +
              "'trace-envelope', XMLType('" + traceData + "'))";
         where 'traceData' is some new XML data for insertion. The view on the row then becomes (for example):
         0, XMLTYPE('<trace-envelope>
                   <metadata>
                        <pid>12345</pid>
                        <date>2008-05-30</date>
                   </metadata>
                   <EP>
                        <priceDate>
                             2008-05-30
                        </priceDate>
                   </EP>
              </trace-envelope>')
    iv)     Continue appending successive child nodes.

    The only thing I currently can think of is maybe a negative impact of updating / re-balancing the index tree during appending in the XMLType OR structure.
    SQL> select * from user_segments where segment_type like '%INDEX%'
      2  order by segment_type
      3  /
    SEGMENT_NAME                   PARTITION_NAME                 SEGMENT_TYPE       SEGMENT_SU TABLESPACE_NAME                    BYTES    BLOCKS   EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS  MAX_SIZE RETENTI MINRETENTION PCT_INCREASE FREELISTS FREELIST_GROUPS BUFFER_
    SYS_C004114                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004115                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004116                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004117                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004118                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004120                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004119                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00005$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00011$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00016$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00025$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060324C00003$$                                      LOBINDEX           ASSM       USERS                             131072        16         2          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060305C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060328C00003$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    15 rows selected.
    SQL> select * from user_segments
      2  /
    SEGMENT_NAME                   PARTITION_NAME                 SEGMENT_TYPE       SEGMENT_SU TABLESPACE_NAME                    BYTES    BLOCKS   EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS  MAX_SIZE RETENTI MINRETENTION PCT_INCREASE FREELISTS FREELIST_GROUPS BUFFER_
    ACTION_TABLE                                                  NESTED TABLE       ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060305C00004$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060305C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004114                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    LINEITEM_TABLE                                                NESTED TABLE       ASSM       USERS                             131072        16         2          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004115                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    PURCHASEORDER_OR                                              TABLE              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00004$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00005$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00005$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00011$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00011$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00016$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00016$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00025$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00025$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004116                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004117                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004118                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    PURCHASEORDER_CLOB                                            TABLE              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060324C00003$$                                     LOBSEGMENT         ASSM       USERS                           14680064      1792        29          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060324C00003$$                                      LOBINDEX           ASSM       USERS                             131072        16         2          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004119                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    PURCHASEORDER_CSX                                             TABLE              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060328C00003$$                                     LOBSEGMENT         SECUREFILE USERS                             327680        40         4         106496                       1   2.147E+09 2.147E+09 DEFAULT            0                                        DEFAULT
    SYS_IL0000060328C00003$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004120                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    28 rows selected.
    SQL> select dbms_lob.getlength(t.xmldata)
      2         as "XMLDocSize"
      3  from   PURCHASEORDER_CLOB t;
    XMLDocSize
         73114
    1 row selected.
    SQL>
    SQL> select dbms_lob.getlength(t.object_value.getclobval())
      2         as "XMLDocSize"
      3  from   PURCHASEORDER_CSX t;
    XMLDocSize
         68682
    1 row selected.
    SQL>
    SQL> select dbms_lob.getlength(t.object_value.getclobval())
      2         as "XMLDocSize"
      3  from   PURCHASEORDER_OR t;
    XMLDocSize
         85342
    1 row selected.
    SQL>
    SQL> truncate table PURCHASEORDER_CLOB;
    Table truncated.
    SQL> truncate table PURCHASEORDER_CSX;
    Table truncated.
    SQL> truncate table PURCHASEORDER_OR;
    Table truncated.
    SQL> var DOCUMENT VARCHAR2(4000)
    SQL> --
    SQL> set define off
    SQL> --
    SQL> begin
      2    :DOCUMENT :=
      3  '<PurchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PurchaseOrder.xsd">
      4     <Reference>AMCEWEN-20030409123336271PDT</Reference>
      5     <Actions>
      6             <Action>
      7                     <User>KPARTNER</User>
      8             </Action>
      9     </Actions>
    10     <Reject/>
    11     <Requestor>Allan D. McEwen</Requestor>
    12     <User>AMCEWEN</User>
    13     <CostCenter>S30</CostCenter>
    14     <ShippingInstructions>
    15             <name>Allan D. McEwen</name>
    16             <address>Oracle Plaza
    17  Twin Dolphin Drive
    18  Redwood Shores
    19  CA
    20  94065
    21  USA</address>
    22             <telephone>650 506 7700</telephone>
    23     </ShippingInstructions>
    24     <SpecialInstructions>Expidite</SpecialInstructions>
    25     <LineItems>
    26             <LineItem ItemNumber="1">
    27                     <Description>Traffic</Description>
    28                     <Part Id="696306038924" UnitPrice="39.95" Quantity="2"/>
    29             </LineItem>
    30             <LineItem ItemNumber="2">
    31                     <Description>General Idi Amin Dada</Description>
    32                     <Part Id="37429166529" UnitPrice="29.95" Quantity="3"/>
    33             </LineItem>
    34             <LineItem ItemNumber="3">
    35                     <Description>This is Spinal Tap</Description>
    36                     <Part Id="715515009126" UnitPrice="39.95" Quantity="3"/>
    37             </LineItem>
    38             <LineItem ItemNumber="4">
    39                     <Description>Great Expectations</Description>
    40                     <Part Id="37429128022" UnitPrice="39.95" Quantity="1"/>
    41             </LineItem>
    42             <LineItem ItemNumber="5">
    43                     <Description>The Unbearable Lightness Of Being</Description>
    44                     <Part Id="37429140222" UnitPrice="29.95" Quantity="2"/>
    45             </LineItem>
    46             <LineItem ItemNumber="6">
    47                     <Description>Blood of a Poet</Description>
    48                     <Part Id="37429147429" UnitPrice="0.0" Quantity="1"/>
    49             </LineItem>
    50             <LineItem ItemNumber="7">
    51                     <Description>Juliet of the Spirits</Description>
    52                     <Part Id="37429165829" UnitPrice="29.95" Quantity="4"/>
    53             </LineItem>
    54             <LineItem ItemNumber="8">
    55                     <Description>Insomnia</Description>
    56                     <Part Id="37429138229" UnitPrice="29.95" Quantity="4"/>
    57             </LineItem>
    58             <LineItem ItemNumber="9">
    59                     <Description>Picnic at Hanging Rock</Description>
    60                     <Part Id="37429126325" UnitPrice="29.95" Quantity="3"/>
    61             </LineItem>
    62             <LineItem ItemNumber="10">
    63                     <Description>W.C. Fields - Six Short Films</Description>
    64                     <Part Id="715515010726" UnitPrice="29.95" Quantity="4"/>
    65             </LineItem>
    66     </LineItems>
    67  </PurchaseOrder>';
    68  end;
    69  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> set timing on
    SQL>  --
    SQL> insert into PURCHASEORDER_OR values ( XMLType(:DOCUMENT))
      2  /
    1 row created.
    Elapsed: 00:00:00.06
    SQL>
    SQL> insert into PURCHASEORDER_CLOB values ( XMLType(:DOCUMENT))
      2   /
    1 row created.
    Elapsed: 00:00:00.01
    SQL>
    SQL> insert into PURCHASEORDER_CSX values ( XMLType(:DOCUMENT))
      2  /
    1 row created.
    Elapsed: 00:00:00.03
    SQL> commit;
    Commit complete.
    Elapsed: 00:00:00.01
    SQL> create or replace synonym PURCHASEORDER for PURCHASEORDER_OR
      2  /
    Synonym created.
    Elapsed: 00:00:00.03
    SQL> call appendLineItems(1001,2000)
      2  /
    Call completed.
    Elapsed: 00:00:04.78
    SQL> call appendLineItems(2001,3000)
      2  /
    Call completed.
    Elapsed: 00:00:09.39
    SQL> call appendLineItems(3001,4000)
      2  /
    Call completed.
    Elapsed: 00:00:13.93
    SQL> call appendLineItems(4001,5000)
      2  /
    Call completed.
    Elapsed: 00:00:18.70
    SQL> call appendLineItems(5001,6000)
      2  /
    Call completed.
    Elapsed: 00:00:23.65
    SQL> call appendLineItems(6001,7000)
      2  /
    Call completed.
    Elapsed: 00:00:28.18
    SQL> call appendLineItems(7001,8000)
      2  /
    Call completed.
    Elapsed: 00:00:32.98
    SQL> call appendLineItems(8001,9000)
      2  /
    Call completed.
    Elapsed: 00:00:37.78
    SQL> call appendLineItems(9001,10000)
      2  /
    Call completed.
    Elapsed: 00:00:43.03
    SQL> select * from user_segments where segment_type like '%INDEX%'
      2  order by segment_type;
    SEGMENT_NAME                   PARTITION_NAME                 SEGMENT_TYPE       SEGMENT_SU TABLESPACE_NAME                    BYTES    BLOCKS   EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS  MAX_SIZE RETENTI MINRETENTION PCT_INCREASE FREELISTS FREELIST_GROUPS BUFFER_
    SYS_C004114                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004115                                                   INDEX              ASSM       USERS                             393216        48         6          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004116                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004117                                                   INDEX              ASSM       USERS                             196608        24         3          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004118                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004120                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004119                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00005$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00011$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00016$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00025$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060324C00003$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060305C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060328C00003$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    15 rows selected.
    Elapsed: 00:00:00.17
    SQL> select * from user_segments;
    SEGMENT_NAME                   PARTITION_NAME                 SEGMENT_TYPE       SEGMENT_SU TABLESPACE_NAME                    BYTES    BLOCKS   EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS  MAX_SIZE RETENTI MINRETENTION PCT_INCREASE FREELISTS FREELIST_GROUPS BUFFER_
    ACTION_TABLE                                                  NESTED TABLE       ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060305C00004$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060305C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004114                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    LINEITEM_TABLE                                                NESTED TABLE       ASSM       USERS                             917504       112        14          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004115                                                   INDEX              ASSM       USERS                             393216        48         6          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    PURCHASEORDER_OR                                              TABLE              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00004$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00004$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00005$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00005$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00011$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00011$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00016$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00016$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060304C00025$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060304C00025$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004116                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004117                                                   INDEX              ASSM       USERS                             196608        24         3          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004118                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    PURCHASEORDER_CLOB                                            TABLE              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060324C00003$$                                     LOBSEGMENT         ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_IL0000060324C00003$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004119                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    PURCHASEORDER_CSX                                             TABLE              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_LOB0000060328C00003$$                                     LOBSEGMENT         SECUREFILE USERS                             131072        16         1         106496                       1   2.147E+09 2.147E+09 DEFAULT            0                                        DEFAULT
    SYS_IL0000060328C00003$$                                      LOBINDEX           ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    SYS_C004120                                                   INDEX              ASSM       USERS                              65536         8         1          65536                       1   2.147E+09 2.147E+09                                                             DEFAULT
    28 rows selected.
    Elapsed: 00:00:00.17
    SQL> select index_name, table_name, blevel, LEAF_BLOCKS, DISTINCT_KEYS, AVG_LEAF_BLOCKS_PER_KEY, AVG_DATA_BLOCKS_PER_KEY
      2  from user_indexes
      3  ;
    INDEX_NAME                     TABLE_NAME                        BLEVEL LEAF_BLOCKS DISTINCT_KEYS AVG_LEAF_BLOCKS_PER_KEY AVG_DATA_BLOCKS_PER_KEY
    SYS_C004114                    ACTION_TABLE                           0           1             1                       1                       1
    SYS_IL0000060305C00004$$       ACTION_TABLE
    SYS_C004115                    LINEITEM_TABLE                         1           2           511                       1                       1
    SYS_C004119                    PURCHASEORDER_CLOB                     0           1             1                       1                       1
    SYS_IL0000060324C00003$$       PURCHASEORDER_CLOB
    SYS_C004120                    PURCHASEORDER_CSX                      0           1             1                       1                       1
    SYS_IL0000060328C00003$$       PURCHASEORDER_CSX
    SYS_C004116                    PURCHASEORDER_OR                       0           1             1                       1                       1
    SYS_IL0000060304C00025$$       PURCHASEORDER_OR
    SYS_IL0000060304C00016$$       PURCHASEORDER_OR
    SYS_IL0000060304C00011$$       PURCHASEORDER_OR
    SYS_IL0000060304C00005$$       PURCHASEORDER_OR
    SYS_IL0000060304C00004$$       PURCHASEORDER_OR
    SYS_C004117                    PURCHASEORDER_OR                       0           1             1                       1                       1
    SYS_C004118                    PURCHASEORDER_OR                       0           1             1                       1                       1
    15 rows selected.
    Elapsed: 00:00:00.15
    SQL> select dbms_lob.getlength(t.object_value.getclobval())
      2         as "XMLDocSize"
      3  from   PURCHASEORDER_OR t;
    XMLDocSize
       1505177
    1 row selected.
    Elapsed: 00:00:00.42
    SQL> set autotrace ON EXPLAIN
    SQL> select count(*) from PURCHASEORDER, XMLTABLE (
      2  '/PurchaseOrder/LineItems/LineItem' passing OBJECT_VALUE)
      3  /
    COUNT(*)
         9010
    1 row selected.
    Elapsed: 00:00:00.07
    Execution Plan
    Plan hash value: 3089669143
    | Id  | Operation           | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |                  |     1 |    53 |     9  (12)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |                  |     1 |    53 |            |          |
    |*  2 |   HASH JOIN         |                  |   511 | 27083 |     9  (12)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| PURCHASEORDER_OR |     1 |    34 |     3   (0)| 00:00:01 |
    |*  4 |    TABLE ACCESS FULL| LINEITEM_TABLE   |   511 |  9709 |     5   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("NESTED_TABLE_ID"="PURCHASEORDER"."SYS_NC0003200033$")
       4 - filter("SYS_NC_TYPEID$" IS NOT NULL)

  • Suggestions to improve the INSERT performance

    Hi All,
    I have a table which has 170 columns .
    I am inserting huge data 50K and more records into this table.
    my insert would be look like this.
    INSERT INTO /*+ append */ REPORT_DATA(COL1,COL2,COL3,COL4,COL5,COL6)
    SELECT  DATA1,DATA2,DATA3,DATA4,DATA5,DATA5 FROM TXN_DETAILS
    WHERE COL1='CA';
    Here i want to insert values for only few columns.Hence i specifies only those column names in insert statement.
    But when huge data(50k+) returned by select query then this statement taking   very long time to execute(approximately 10 to 15 mins).
    Please  suggest me to improve this insert statement performance.I am also using 'append' hint.
    Thanks in advance.

    a - Disable/drop indexes and constraints - It's far faster to rebuild indexes after the data load, all at-once. Also indexes will rebuild cleaner, and with less I/O if they reside in a tablespace with a large block size.
    b - Manage segment header contention for parallel inserts - Make sure to define multiple freelist (or freelist groups) to remove contention for the table header. Multiple freelists add additional segment header blocks, removing the bottleneck.  You can also use Automatic Segment Space Managementhttp://www.dba-oracle.com/art_dbazine_ts_mgt.htm (bitmap freelists) to support parallel DML, but ASSM has some limitations
    c - Parallelize the load - You can invoke parallel DML (i.e. using the PARALLEL and APPEND hint) to have multiple inserts into the same table. For this INSERT optimization, make sure to define multiple freelists and use the SQL "APPEND" option. If you submit parallel jobs to insert against the table at the same time, using the APPEND hint may cause serialization, removing the benefit of parallel jobstreams.
    d - APPEND into tables - By using the APPEND hint, you ensure that Oracle always grabs "fresh" data blocks by raising the high-water-mark for the table. If you are doing parallel insert DML, the Append mode is the default and you don't need to specify an APPEND hint. Also, if you're going w/ APPEND, consider putting the table into NOLOGGING mode, which will allow Oracle to avoid almost all redo logging."
    insert /*+ append */ into customer values ('hello',';there');
    e - Use a large blocksize - By defining large (i.e. 32k) blocksizes for the target table, you reduce I/O because more rows fit onto a block before a "block full" condition (as set by PCTFREE) unlinks the block from the freelist.
    f - Use  NOLOGGING
    f - RAM disk - You can use high-speed solid state disk (RAM-SAN) to make Oracle inserts run up to 300x faster than platter disk.

  • Best Practice PK Generation: 'before insert on trig' vs. rolling yer own

    Experts,
    I have a form with the standard Create/Delete/Apply Changes buttons.
    When someone hits "Create", I have a trigger that fires on the table as "before insert on". It hits a sequence to get a new primary key for the record which is about to be created.
    Another way of doing it is to run a page-level PL/SQL computation, and get SEQUENCE_NAME.Nextval, and stuff it into the appropriate page-level item. "Create" will then fire the insert after this computation and it amounts to the same thing as the trigger.
    Loaded question: Which way is better?
    My DBA recommends to "roll my own" using the page-level computation. His reasoning is if my applications scale up to a lot of users running inserts at the same time, the trigger will be a bit of a drag.
    On the other hand, I like having the trigger "on the database" and not having to worry much about it. It is one less thing that I have on my page.
    Dan

    I'm not the end-all be-all of Oracle expertise, so I
    refer to those who are:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P1
    1_QUESTION_ID:4343369880986#34562653805149
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P1
    1_QUESTION_ID:4343369880986#76218085672062
    A couple links I could quickly find on the subject.
    I'm sure there's plenty more out there.Taking Tom's answers out of context don't invalidate the problems of a trigger"less" approach.
    As to the other concerns, personally I would argue
    that a separation between application logic and GUI
    shouldn't go so far as to remove all data management
    concerns, such as using primary keys (and otherwise
    indexed fields) to access data.Still, what happens if you want to user other methods of access, for example sqlldr/external tables, ODBC/.NET, etc.?
    Also, I prefer to keep rogue applications/scripts
    away from my data if possible :). Translated: Everyone has to incorporate sequences in any INSERT statement. For BULK inserts, this maybe the way to go, but you can always check if the PK column is NULL, which should give the trigger a bit of performance improvement.
    But on the chance
    that they do go selecting from incorrect sequences it
    will be their own problem. Or your's if other applications start generating error messages.
    It'll be refused insert
    until it can (randomly, I don't care) provide a
    unique value for that column. Yay for constraints!Finding the source of the problem might be where unnecessary work has to be put in.
    I agree there are a few valid uses for such a
    trigger, I've done it myself. But on the whole, it's
    best to avoid it when possible.Can't follow your argument, really. Maybe another agree to disagree topic?
    C.

Maybe you are looking for

  • Is it possible to make an ImageIcon array?

    Hi, I have been having some strange problems with ImageIcon... Here is my code... ImageIcon tiles[][] = new ImageIcon[5][5]; tiles[0][0] = "1.png"; I know this is not right, but basically, I want to make a 2dimensional array of imageIcon's, and then

  • FM for fetching partners corresponding to project

    Hi, Is there any Fm for fetching  the partners ( BP) corresponding to a project which is stored in table cgpl_project. Thanks, Swati.

  • Lack Permission to access Network Home Directory

    I upgraded OSX 10.4.8 Server to 10.4.9. I also updated the client computers to the same. The server is a Master LDAP directory which houses the users home directories. Since the upgrade when a user tried to login to their home directory they receive

  • IdM 6.0 SPE SP1 querying LDAP for changenumbers

    We are using IdM 6.0 SPE SP1 to manage creates and updates to a Sun One Directory Server 5.2. In looking at the access logs, we are seeing lots of LDAP queries for cn=changenumbers. What is changenumber being used for? We are not using ActiveSync or

  • Unable to access dashboard  in infoview

    Hi, I am unable to open/create dashnoard ( created by administrator) in infoview thorugh user login, although given access rights to PM repository server, dashboard server, analytical server to the all users through . it gives following error: An err