What is the fastest way to insert data into an Oracle table?

前端 未结 8 2024
逝去的感伤
逝去的感伤 2020-12-30 07:22

I am writing a data conversion in PL/SQL that processes data and loads it into a table. According to the PL/SQL Profiler, one of the slowest parts of the conversion is the a

相关标签:
8条回答
  • 2020-12-30 07:40

    Check this link http://www.dba-oracle.com/t_optimize_insert_sql_performance.htm

    1. main points to consider for your case is to use Append hint as this will directly append into the table instead of using freelist. If you can afford to turn off logging than use append with nologging hint to do it
    2. Use a bulk insert instead instead of iterating in PL/SQL
    3. Use sqlloaded to load the data directly into the table if you are getting data from a file feed
    0 讨论(0)
  • 2020-12-30 07:40

    Maybe one of your best option is to avoid Oracle as much as possible actually. I've been baffled by this myself, but very often a Java process can outperform many of the Oracle's utilities which either use OCI (read: SQL Plus) or will take up so much of your time to get right (read: SQL*Loader).

    This doesn't prevent you to use specific hints either (like /APPEND/).

    I've been pleasantly surprised each time I've turned to that kind of solution.

    Cheers,

    Rollo

    0 讨论(0)
  • 2020-12-30 07:51

    It's much better to insert a few hundred rows at a time, using PL/SQL tables and FORALL to bind into insert statement. For details on this see here.

    Also be careful with how you construct the PL/SQL tables. If at all possible, prefer to instead do all your transforms directly in SQL using "INSERT INTO t1 SELECT ..." as doing row-by-row operations in PL/SQL will still be slower than SQL.

    In either case, you can also use direct-path inserts by using INSERT /*+APPEND*/, which basically bypasses the DB cache and directly allocates and writes new blocks to data files. This can also reduce the amount of logging, depending on how you use it. This also has some implications, so please read the fine manual first.

    Finally, if you are truncating and rebuilding the table it may be worthwhile to first drop (or mark unusable) and later rebuild indexes.

    0 讨论(0)
  • 2020-12-30 07:53

    Suppose you have taken eid,ename,sal,job. So create a table first as:

    SQL>create table tablename(eid number, ename varchar2(20),sal number,job char(10));
    

    Now insert data:-

    SQL>insert into tablename values(&eid,'&ename',&sal,'&job');
    
    0 讨论(0)
  • 2020-12-30 07:54

    If dropping the index doesn't speed things up enough, you need the Oracle SQL*Loader:

    http://www.oracle.com/technology/products/database/utilities/htdocs/sql_loader_overview.html

    0 讨论(0)
  • 2020-12-30 07:57

    Regular insert statements are the slowest way to get data in a table and not meant for bulk inserts. The following article references a lot of different techniques for improving performance: http://www.dba-oracle.com/oracle_tips_data_load.htm

    0 讨论(0)
提交回复
热议问题