SQLLDR——CTL檔案:欄位設定
position 關鍵字用來指定列的開始和結束位置
position(m:n):指從第 m 個字元開始截止到第 n 個字元作為列值
position(*+2:15):直接指定數值的方式叫做絕對偏移量,如果使用*號,則為相對偏移量,表示上一個欄位哪裡結束,這次就哪裡開始,相對便宜量也可以再做運算。
position(*) char(9):這種相對偏移量+型別和長度的優勢在於,你只需要為第一列指定開始位置,其他列只需要指定列長度就可以。
FILLER:控制檔案中指定 FILLER,表示該列值不匯入表中。
普通
- Load DATA
- INFILE *
- INTO TABLE BONUS
- FIELDS TERMINATED BY ","
- (ENAME,JOB,SAL)
- BEGINDATA
- SMITH,CLEAK,3904
- ALLEN,SALESMAN,2891
- WARD,SALESMAN,3128
- KING,PRESIDENT,2523
沒有分隔符
- LOAD DATA
- INFILE *
- TRUNCATE INTO TABLE BONUS
- (
- ENAME position(1:5),
- JOB position(7:15),
- SAL position(17:20)
- )
- BEGINDATA
- SMITH CLEAK 2891
- ALLEN SALESMAN 2891
- WARD SALESMAN 3128
- KING PRESIDENT 2523
比匯入的表列少
- LOAD DATA
- INFILE *
- TRUNCATE INTO TABLE BONUS
- (
- ENAME position(1:5),
- JOB position(7:15),
- SAL position(17:20),
- comm "0"
- )
- BEGINDATA
- SMITH CLEAK 2891
- ALLEN SALESMAN 2891
- WARD SALESMAN 3128
- KING PRESIDENT 2523
比匯入的表列多
- LOAD DATA
- INFILE *
- TRUNCATE INTO TABLE BONUS
- (
- ENAME position(1:6),
- TCOL FILLER position(8:11),
- JOB position(13:21),
- SAL position(23:26)
- )
- BEGINDATA
- SMITH 7369 CLERK 800 20
- ALLEN 7499 SALESMAN 1600 30
- WARD 7521 SALESMAN 1250 30
- JONES 7566 MANAGER 2975 20
- MARTIN 7654 SALESMAN 1250 30
- BLAKE 7698 MANAGER 2850 30
- CLARK 7782 MANAGER 2450 10
- KING 7839 PRESIDENT 5000 10
- TURNER 7844 SALESMAN 1500 30
- JAMES 7900 CLERK 950 30
- FORD 7902 ANALYST 3000 20
- MILLER 7934 CLERK 1300 10
匯入不同表
- LOAD DATA
- INFILE *
- TRUNCATE
- INTO TABLE BONUS
- WHEN Tab='BON'
- (
- Tab FILLER position(1:3),
- ENAME position(5:9),
- JOB position(11:19),
- SAL position(21:24)
- )
- INTO TABLE MANAGER
- WHEN Tab='MGR'
- (
- Tab FILLER position(1:3),
- MGRNO position(5:6),
- MNAME position(8:14),
- JOB position(16:28)
- )
- BEGINDATA
- BON SMITH CLERK 3904
- BON ALLEN SALER,M 2891
- BON WARD SALER,"S" 3128
- BON KING PRESIDENT 2523
- MGR 10 SMITH SALES MANAGER
- MGR 11 ALLEN.W TECH MANAGER
- MGR 16 BLAKE HR MANAGER
- TMP SMITH 7369 CLERK 800 20
- TMP ALLEN 7499 SALESMAN 1600 30
- TMP WARD 7521 SALESMAN 1250 30
- TMP JONES 7566 MANAGER 2975 20
換行符處理
- LOAD DATA
- INFILE *
- TRUNCATE INTO TABLE BONUS
- FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
- (ENAME,JOB,SAL)
- BEGINDATA
- SMITH,CLEAK,3904
- ALLEN,"SALER,M",2891
- WARD,"SALER,""S""",3182
- KING,PRESIDENT,2523
函式使用
- LOAD DATA
- INFILE *
- TRUNCATE INTO TABLE BONUS
- (
- ENAME position(1:5),
- JOB position(7:15),
- SAL position(17:20),
- comm "substr(:sal,1,1)"
- )
- BEGINDATA
- SMITH CLEAK 3904
- ALLEN SALESMAN 2891
- WARD SALESMAN 3128
- KING PRESIDENT 2523
大欄位處理
- LOAD DATA
- INFILE * "str '\r\n'"
- TRUNCATE INTO TABLE MANAGER
- FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
- (MGRNO,MNAME,JOB,REMARK char(100000))
- BEGINDATA
- 10,SMITH,SALES MANAGER,This is SMITH.
- He is a Sales Manager.|
- 11,ALLEN.W,TECH MANAGER,This is ALLEN.W.
- He is a Tech Manager.|
- 16,BLAKE,HR MANAGER,"This is BLAKE. He is a Hr Manager. The jobs responsibilities are in the following:
- 1. Ensure the effective local implementation of corporate level HRinitiatives and new programs.
- 2. Take initiatives in defining HR strategy on attracting, hiring, integrating, developing, managing, rewarding and retaining talents for the sustainable development of company business.
- 3. Oversee stanard recruiting an procedures to ensure the company's staffing requirements are met in a timely manner, and interview management level candidates
- 4. Provide employees with fair and appropriate compensation and benefit, to ensure market competitiveness.
- 5. Develop, implement and oversee the training and development programs to upgrade the skills of the employee and to enhance the company's capabilities to met business goals and future challenges."
載入檔案內容到大欄位
- LOAD DATA
- INFILE *
- TRUNCATE INTO TABLE LOBTBL
- (
- CREATE_DATE POSITION(1:17) DATE 'YYYY-MM-DD HH24:MI',
- FILESIZE POSITION(*+1:25) "to_number(:FILESIZE, '99,999,999')",
- FILEOWNER POSITION(*+1:34),
- FILENAME POSITION(*+1) char(200) "substr(:FILENAME,instr(:FILENAME, '\\',-1)+1)",
- FILEDATA LOBFILE(FILENAME) TERMINATED BY EOF
- )
- BEGINDATA
- 2009-03-17 09:43 154 JUNSANSI F:\oracle\script\ldr_case11_1.ctl
- 2009-03-17 09:44 189 JUNSANSI F:\oracle\script\ldr_case11_1.dat
- 2009-03-17 09:44 2,369 JUNSANSI F:\oracle\script\ldr_case11_1.log
- 2009-03-16 16:50 173 JUNSANSI F:\oracle\script\ldr_case11_2.ctl
- 2009-03-16 16:49 204 JUNSANSI F:\oracle\script\ldr_case11_2.dat
- 2009-03-16 16:50 1,498 JUNSANSI F:\oracle\script\ldr_case11_2.log
- 2009-03-16 17:41 145 JUNSANSI F:\oracle\script\ldr_case11_3.ctl
- 2009-03-16 17:44 130 JUNSANSI F:\oracle\script\ldr_case11_3.dat
- 2009-03-16 17:44 1,743 JUNSANSI F:\oracle\script\ldr_case11_3.log
- 2009-03-17 11:01 132 JUNSANSI F:\oracle\script\ldr_case11_4.ctl
- 2009-03-17 11:02 188 JUNSANSI F:\oracle\script\ldr_case11_4.dat
- 2009-03-17 11:02 1,730 JUNSANSI F:\oracle\script\ldr_case11_4.log
載入每行的行號
- load data
- infile *
- into table t
- replace
- (
- seqno RECNUM //載入每行的行號
- text Position(1:1024)
- )
- BEGINDATA
- testline1
- testline2
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24851054/viewspace-2149012/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle OCP(55):SQLLDR—CTL檔案OracleSQL
- sql設定欄位預設值SQL
- MySQL欄位預設值設定詳解MySql
- ElasticSearch 設定某個欄位不分詞Elasticsearch分詞
- SharePoint 多行文字欄位設定預設值
- /etc/shadow檔案相關欄位的解釋
- 為React Ant-Design Table增加欄位設定React
- 將資料庫照片大欄位下卸到檔案系統,照片檔名以某一個欄位命名資料庫
- MySQL欄位究竟是否需要設定成not nullMySqlNull
- [提問交流]建立模型,新增屬性,欄位型別如何設定2位小數的欄位型別模型型別
- 如何找出兩個文字檔案中有相同欄位的行
- pydantic 欄位的預設值設定獲取當前時間
- Django 公共模型欄位的設定和繼承(AuditBaseModel、ApprovalBaseModel)Django模型繼承APP
- 設定 Windows Media Player 推薦設定的登錄檔檔案Windows
- ssh配置檔案安全設定
- Lumen 檔案上傳設定
- iOS SVN忽略檔案設定iOS
- Java 如何找出兩個文字檔案中有相同欄位的行Java
- SqlSugar code first 欄位為列舉型別,預設生成資料庫欄位為bigint如何設定為int型別SqlSugar型別資料庫
- word分欄怎麼設定 word設定分欄的方法
- dcat欄位擴充套件:地圖拖拽設定xy座標套件地圖
- Archlinux 設定休眠到swap檔案Linux
- 管理(005):密碼檔案設定密碼
- idea檔案頭資訊設定Idea
- Dynamics CRM 通過配置來設定查詢欄位的預設檢視
- pydantic 欄位欄位校驗
- 設定儲存檔案的目錄
- Next 設定字型檔案cdn 或者本地
- pycharm設定python標頭檔案模版PyCharmPython
- 如何給PDF檔案設定密碼?密碼
- 如何實現檔案共享,檔案共享的設定方法-鐳速
- MySQL 5.7 datetime和timestamp欄位設定default 0 插入資料包錯MySql
- 查詢oracle欄位預設值Oracle
- oracle增加欄位帶預設值Oracle
- 一個Java檔案解決mybatis呼叫資料庫欄位與Java類檔案屬性不對應JavaMyBatis資料庫
- sublime設定儲存新檔案時的預設檔案型別(字尾名)型別
- MySQL的配置檔案的引數設定MySql
- Host是什麼?如何設定host檔案?
- java配置檔案設定絕對路徑Java