关于SQL*Loader的用法

网上有很多好文,贴出网址以及一些摘要:

1、关于 Oracle 的数据导入导出及 Sql Loader (sqlldr) 的用法

http://www.blogjava.net/Unmi/archive/2009/01/05/249956.html

2、使用手册

http://www.psoug.org/reference/sqlloader.html

3、sqlldr语法

http://yumianfeilong.com/html/2007/03/20/49.html

4、faq

http://www.orafaq.com/wiki/SQL*Loader_FAQ

5、sqlloader,这篇很值得一看。

http://www.oracleutilities.com/OSUtil/sqlldr.html

其中写了一个自动生成控制文件的脚本:

——————————————————————
set echo off ver off feed off pages 0

accept tname prompt ‘Enter Name of Table: ‘
accept dformat prompt ‘Enter Format to Use for Date Columns: ‘

spool &tname..ctl

select ‘LOAD DATA’|| chr (10) ||
‘INFILE ”’ || lower (table_name) || ‘.dat”’ || chr (10) ||
‘INTO TABLE ‘|| table_name || chr (10)||
‘FIELDS TERMINATED BY ”,”’||chr (10)||
‘TRAILING NULLCOLS’ || chr (10) || ‘(‘
from   user_tables
where  table_name = upper (‘&tname’);

select decode (rownum, 1, ‘   ‘, ‘ , ‘) ||
rpad (column_name, 33, ‘ ‘)      ||
decode (data_type,
‘VARCHAR2′, ‘CHAR NULLIF (‘||column_name||’=BLANKS)’,
‘FLOAT’,    ‘DECIMAL EXTERNAL NULLIF(‘||column_name||’=BLANKS)’,
‘NUMBER’,   decode (data_precision, 0,
‘INTEGER EXTERNAL NULLIF (‘||column_name||
‘=BLANKS)’, decode (data_scale, 0,
‘INTEGER EXTERNAL NULLIF (‘||
column_name||’=BLANKS)’,
‘DECIMAL EXTERNAL NULLIF (‘||
column_name||’=BLANKS)’)),
‘DATE’,     ‘DATE “&dformat” NULLIF (‘||column_name||’=BLANKS)’, null)
from   user_tab_columns
where  table_name = upper (‘&tname’)
order  by column_id;

select ‘)’
from dual;

spool off
——————————————————————

另外提到了几种高效率的使用sqlldr的方法:

1. Use Direct Path Loads – The conventional path loader essentially loads the data by using standard insert statements. The direct path loader (direct=true) loads directly into the Oracle data files and creates blocks in Oracle database block format. The fact that SQL is not being issued makes the entire process much less taxing on the database. There are certain cases, however, in which direct path loads cannot be used (clustered tables). To prepare the database for direct path loads, the script $ORACLE_HOME/rdbms/admin/catldr.sql.sql must be executed.

2. Disable Indexes and Constraints. For conventional data loads only, the disabling of indexes and constraints can greatly enhance the performance of SQL*Loader.

3. Use a Larger Bind Array. For conventional data loads only, larger bind arrays limit the number of calls to the database and increase performance. The size of the bind array is specified using the bindsize parameter. The bind array’s size is equivalent to the number of rows it contains (rows=) times the maximum length of each row.

4. Use ROWS=n to Commit Less Frequently. For conventional data loads only, the rows parameter specifies the number of rows per commit. Issuing fewer commits will enhance performance.

5. Use Parallel Loads. Available with direct path data loads only, this option allows multiple SQL*Loader jobs to execute concurrently.

$ sqlldr control=first.ctl parallel=true direct=true

$ sqlldr control=second.ctl parallel=true direct=true

6. Use Fixed Width Data. Fixed width data format saves Oracle some processing when parsing the data. The savings can be tremendous, depending on the type of data and number of rows.

7. Disable Archiving During Load. While this may not be feasible in certain environments, disabling database archiving can increase performance considerably.

8. Use unrecoverable. The unrecoverable option (unrecoverable load data) disables the writing of the data to the redo logs. This option is available for direct path loads only.

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>