自動生成sqlldr 控制檔案的指令碼(Script To Generate SQL*Loader Control File)
Script To Generate SQL*Loader Control File (文件 ID 1019523.6)
APPLIES TO:
Oracle
Server - Enterprise Edition - Version 7.3.4.0 to 11.2.0.4 [Release 7.3.4 to
11.2]
Information in this document applies to any
platform.
***Checked for relevance on 22-NOV-2012***
PURPOSE
Script to generate SQL*Loader control file.
REQUIREMENTS
Execution Environment: SQL*Plus
Access Privileges: SELECT privileges on the table
Usage: sqlplus /
@control.sql
Instructions: PROOFREAD THIS SCRIPT BEFORE USING IT! Due to differences in the
way text editors, e-mail packages, and operating systems handle text formatting
(spaces, tabs, and carriage returns), this script may not be in an executable
state when you first receive it. Check over the script to ensure that errors of
this type are corrected. The script will produce an output file named .ctl.
This file can be viewed in a browser or uploaded for support analysis.
CONFIGURING
This script prepares a SQL*Loader control file for a table already existing in the database. The script accepts the table name and automatically creates a file with the table name and extension 'ctl'. This is specially useful if you have the DDL statement to create a particular table and have a free-format ASCII-delimited file but have not yet created a SQL*Loader control file for the loading operation.
Default choices for the file are as follows (alter to your needs):
Delimiter: comma
(',')
INFILE file extension: .dat
DATE format: 'MM/DD/YY'
You may define the Loader Data Types of the other Data Types by revising the DECODE function pertaining to them.
Please note: The name of the table to be unloaded needs to be provided when the script is executed as follows:
SQL> start control.sql emp
Example:
SQL> start control.sql emp
LOAD DATA
INFILE 'EMP.dat'
INTO TABLE EMP
FIELDS TERMINATED BY ','
(
EMPNO
, ENAME
, JOB
, MGR
, HIREDATE DATE "MM/DD/YY"
, SAL
, COMM
, DEPTNO
)
INSTRUCTIONS
No special instructions.
CAUTION
This sample code is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
Proofread this sample code before using it! Due to the differences in the way text editors, e-mail packages and operating systems handle text formatting (spaces, tabs and carriage returns), this sample code may not be in an executable state when you first receive it. Check over the sample code to ensure that errors of this type are corrected.
SAMPLE CODE
SQL*Plus script control.sql:
set echo off
set heading off
set verify off
set feedback off
set show off
set trim off
set pages 0
set concat on
set lines 300
set trimspool on
set trimout on
spool &1..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 all_tables
where table_name = upper ('&1');
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 "MM/DD/YY" NULLIF ('||column_name||'=BLANKS)', null)
from user_tab_columns
where table_name = upper ('&1')
order by column_id;
select ')'
from sys.dual;
spool off
SAMPLE OUTPUT
No sample output included.
DISCLAIMER: EXCEPT WHERE EXPRESSLY PROVIDED OTHERWISE, THE INFORMATION, SOFTWARE, PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS. ORACLE EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ORACLE MAKES NO WARRANTY THAT: (A) THE RESULTS THAT MAY BE OBTAINED FROM THE USE OF THE SOFTWARE WILL BE ACCURATE OR RELIABLE; OR (B) THE INFORMATION, OR OTHER MATERIAL OBTAINED WILL MEET YOUR EXPECTATIONS. ANY CONTENT, MATERIALS, INFORMATION OR SOFTWARE DOWNLOADED OR OTHERWISE OBTAINED IS DONE AT YOUR OWN DISCRETION AND RISK. ORACLE SHALL HAVE NO RESPONSIBILITY FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT RESULTS FROM THE DOWNLOAD OF ANY CONTENT, MATERIALS, INFORMATION OR SOFTWARE.
ORACLE RESERVES THE RIGHT TO MAKE CHANGES OR UPDATES TO THE SOFTWARE AT ANY TIME WITHOUT NOTICE.
LIMITATION OF LIABILITY: IN NO EVENT SHALL ORACLE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR USE, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT, ARISING FROM YOUR ACCESS TO, OR USE OF, THE SOFTWARE.
SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OR EXCLUSION OF LIABILITY. ACCORDINGLY, SOME OF THE ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21754115/viewspace-1723368/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SCRIPT TO GENERATE SQL*LOADER CONTROL FILESQL
- 自動ftp,生成control file,sql*load的shell指令碼FTPSQL指令碼
- 控制檔案-control file
- control file(控制檔案)
- 輸入表名後自動生成sqlldr控制檔案儲存過程SQL儲存過程
- 網頁檔案自動下載入庫指令碼_shell_sqlldr網頁指令碼SQL
- 重建控制檔案 recreate control file
- Oracle Control File(控制檔案)的內容Oracle
- SQL Server映象自動生成指令碼方法SQLServer指令碼
- Oracle SQL Loader(sqlldr)OracleSQL
- Oracle 11gR2 RMAN 配置控制檔案自動備份(control file autobackup)Oracle
- Oracle 快照控制檔案(snapshot control file)Oracle
- Oracle快照控制檔案(snapshot control file)Oracle
- 【SQL*Loader】sqlldr匯入SQL
- 自動生成Statspack的指令碼指令碼
- 【SQLLDR】使用SQL*Loader輔助生成外部表建立語句SQL
- oracle sqlldr控制檔案模板OracleSQL
- Oracle SQL Loader(sqlldr)+ Externale TablesOracleSQL
- PowerDesigner: 利用sql指令碼檔案逆生成模型SQL指令碼模型
- 透過Snapshot Control File 恢復控制檔案
- 通過Snapshot Control File 恢復控制檔案
- sql loader的控制檔案可否使用變數variable嗎SQL變數
- 建立自啟動檔案指令碼的例項指令碼
- Script to generate AWR report from remote sql clientREMSQLclient
- shell 備份檔案指令碼+自動清理指令碼
- 利用shell指令碼生成動態sql指令碼SQL
- 自動生成ASH報告指令碼指令碼
- AWR報告自動生成指令碼指令碼
- 自動生成awr報告指令碼指令碼
- 指令碼定期自動刪除ASM下的歸檔檔案指令碼ASM
- 控制檔案相關 -- MAXLOGHISTORY ,control_file_record_keep_time
- 一個自動生成oracle job的指令碼Oracle指令碼
- 使用sql生成sql指令碼SQL指令碼
- sqlldr配合shell解決sqlldr 控制檔案中引入變數的方案SQL變數
- oracle檔案管理之 control fileOracle
- shell指令碼自動清理超過指定大小的檔案指令碼
- 自動生成Mybatis的Mapper檔案MyBatisAPP
- awr報告每天自動生成指令碼指令碼