自動生成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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL Server映象自動生成指令碼方法SQLServer指令碼
- PowerDesigner: 利用sql指令碼檔案逆生成模型SQL指令碼模型
- shell 備份檔案指令碼+自動清理指令碼
- ORACLE 控制檔案(Control Files)概述Oracle
- 轉:Intellij idea Version Control File Status Colors ( 版本控制檔案狀態顏色 )IntelliJIdea
- 自動生成Mybatis的Mapper檔案MyBatisAPP
- Console 自動生成 Model 檔案
- CMD 執行大檔案SQL指令碼SQL指令碼
- awr報告每天自動生成指令碼指令碼
- 第22篇 生成proto檔案bat指令碼BAT指令碼
- Oracle OCP(55):SQLLDR—CTL檔案OracleSQL
- java 自動升級sql指令碼 flyway 工具JavaSQL指令碼
- Script to Collect Log File Sync Diagnostic Information (lfsdiag.sql)ORMSQL
- 自動化運維-修改主機名&hosts檔案指令碼運維指令碼
- 動態引用外部的Javascript指令碼檔案JavaScript指令碼
- 自動生成檔案層級樹類
- 用bat指令碼自動生成安裝包InnosetupBAT指令碼
- flyway實現java 自動升級SQL指令碼JavaSQL指令碼
- pyautogui模組,PC自動化指令碼,控制滑鼠GUI指令碼
- SQLSERVER匯出TXT文字檔案,ORACLE SQL LOADER匯入TXT文字檔案SQLServerOracle
- 前端專案nodejs自動部署指令碼前端NodeJS指令碼
- 使用CukeTest建立指令碼自動化備份檔案到網盤指令碼
- OMF管理自動新增資料檔案指令碼add_datafile.sh指令碼
- mybatis-plus整合springboot自動生成檔案MyBatisSpring Boot
- I/O上的等待事件 —— control file sequential read/control file parallel write事件Parallel
- Generate BKS File( Bouncy Castle KeyStore)AST
- appium 可以用自動化指令碼安裝 release 包的 ipa 檔案麼APP指令碼
- oracle 控制檔案及引數檔案何時自動備份Oracle
- 自定義 loader 讀取 *.vue 檔案原始碼Vue原始碼
- 自動生成Sql--基於Mybatis的單表SqlSQLMyBatis
- 「懶惰的美德」我用 python 寫了個自動生成給文件生成索引的指令碼Python索引指令碼
- vue-cli3 專案優化之通過 node 自動生成元件模板 generate View、ComponentVue優化元件View
- C#指令碼引擎CS-ScriptC#指令碼
- 利用nodejs寫一個自動生成vue元件檔案的cliNodeJSVue元件
- Java動態指令碼Groovy讀取配置檔案Java指令碼
- 使用mybatis-generator自動生成model、dao、mapping檔案MyBatisAPP
- webpack4 系列教程(十三):自動生成HTML檔案WebHTML
- hadoop_批量命令指令碼&同步檔案指令碼Hadoop指令碼
- C#自動檢測檔案的編碼C#