測試TOM=SQLLDR生成外部表
什麼是外部表--簡單說就是可以把作業系統檔案當成是一個只讀的資料庫表
下面測試利用SQLLDR來生成外部表
測試開始
[oracle@oraclelinux ~]$ cat demo1.ctl
LOAD DATA
INFILE *
INTO TABLE DEPT_LOAD
FIELDS TERMINATED BY ','
(DEPTNO, DNAME, LOC )
BEGINDATA
10,Sales,Virginia
20,Accounting,Virginia
30,Consulting,Virginia
40,Finance,Virginia
[oracle@oraclelinux ~]$ sqlldr scott/scott control=demo1.ctl external_table=generate_only;
SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 14 16:51:06 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
以上部分為外部表進行了定義,檢視日誌檔案可以發現實際的SQL語句是怎麼樣的
[oracle@oraclelinux ~]$ cat demo1.log
SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 14 16:51:06 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: demo1.ctl
Data File: demo1.ctl
Bad File: demo1.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation: none specified
Path used: External Table
Table DEPT_LOAD, loaded from every logical record.
Insert option in effect for this table: INSERT
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
DEPTNO FIRST * , CHARACTER
DNAME NEXT * , CHARACTER
LOC NEXT * , CHARACTER
CREATE DIRECTORY statements needed for files
------------------------------------------------------------------------
CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS '/u01/oracle'【在生成外部表指令碼期間,SQLLDR連線到資料庫,並查詢資料字典檢視是否已經存在合適的目錄,在這裡因為沒有合適的目錄所以生成了一個CREATE DIRECTORY語句】
CREATE TABLE statement for external table:
------------------------------------------------------------------------
CREATE TABLE "SYS_SQLLDR_X_EXT_DEPT_LOAD"
(
"DEPTNO" NUMBER(2),
"DNAME" VARCHAR2(14),
"LOC" VARCHAR2(13)
) 【這是生成的建立外部表的語句】
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000【這一部分通知資料庫表不是正常表,不是普通的HEAP表,也不是IOT表,是外部表】
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'demo1.bad'
LOGFILE 'demo1.log_xt'
READSIZE 1048576
SKIP 6
FIELDS TERMINATED BY "," LDRTRIM
REJECT ROWS WITH ALL NULL FIELDS
(
"DEPTNO" CHAR(255)
TERMINATED BY ",",
"DNAME" CHAR(255)
TERMINATED BY ",",
"LOC" CHAR(255)
TERMINATED BY ","
)
) 【這一部分通知資料庫如何處理輸入檔案】
location
(
'demo1.ctl'
)
)REJECT LIMIT UNLIMITED【這通知資料庫所載入的檔名是什麼,這裡指DEMO1.CTL】
INSERT statements used to load internal tables:
------------------------------------------------------------------------
INSERT /*+ append */ INTO DEPT_LOAD
(
DEPTNO,
DNAME,
LOC
)
SELECT
"DEPTNO",
"DNAME",
"LOC"
FROM "SYS_SQLLDR_X_EXT_DEPT_LOAD"[這一部分是生成的INSERT語句,可用於從外部表本身載入資料]
statements to cleanup objects created by previous statements:
------------------------------------------------------------------------
DROP TABLE "SYS_SQLLDR_X_EXT_DEPT_LOAD"
DROP DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000【載入完成之後刪除這前建立的一些物件】
Run began on Mon May 14 16:51:06 2012
Run ended on Mon May 14 16:51:06 2012
Elapsed time was: 00:00:00.48
CPU time was: 00:00:00.07
[oracle@oraclelinux ~]$
接下來為SCOTT使用者分配適當許可權,測試外部表
SQL> show user;
USER is "SYS"
SQL> grant create any directory to scott;
Grant succeeded.
SQL> grant drop any directory to scott;
Grant succeeded.
SQL> select * from dept_load;
no rows selected
從外部表載入資料到DEPT_LOAD;
[oracle@oraclelinux ~]$ sqlldr scott/scott control=demo1.ctl external_table=execute; SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 14 17:45:30 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. [oracle@oraclelinux ~]$ exit exit SQL> select * from dept_load; DEPTNO DNAME LOC ENTIRE_LINE LAST_UPDA ---------- -------------- ------------- ----------------------------- --------- COMMENTS -------------------------------------------------------------------------------- 10 Sales Virginia 20 Accounting Virginia 30 Consulting Virginia DEPTNO DNAME LOC ENTIRE_LINE LAST_UPDA ---------- -------------- ------------- ----------------------------- --------- COMMENTS -------------------------------------------------------------------------------- 40 Finance Virginia SQL> 測試結束
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15720542/viewspace-723555/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle sqlldr 與 外部表OracleSQL
- 測試TOM=SQLLDR使用CASE語句SQL
- 測試TOM=SQLLDR函式使用1SQL函式
- 測試TOM=SQLLDR載入日期資料SQL
- 【SQLLDR】使用SQL*Loader輔助生成外部表建立語句SQL
- 測試TOM==SQLLDR載入固定格式資料SQL
- 測試TOM=SQLLDR使用函式載入資料SQL函式
- 測試oracle sqlldrOracleSQL
- 測試TOM=SQLLDR載入內嵌換行符資料SQL
- oracle外部表的測試學習 (轉)Oracle
- Oracle sqlldr工具功能測試OracleSQL
- sqlldr效能調優測試SQL
- sqlldr中使用條件裝載及作為外部表訪問SQL
- sqlldr批量匯入匯出資料測試SQL
- sqlldr批次匯入匯出資料測試SQL
- Redshift__在一個外部架構下建立外部表後,其他外部架構也自動生成了一樣的外部表架構
- gpt生成測試GPT
- SQLLDR直接載入幾個引數的測試SQL
- 測試TOM=SQLLOADER載入製表符號資料SQL符號
- Java測試框架Automation CenterJava框架
- 測試TOM=SQLLOADER1SQL
- Mock生成測試資料Mock
- shell生成測試資料
- 輸入表名後自動生成sqlldr控制檔案儲存過程SQL儲存過程
- Oracle外部表Oracle
- Oracle 外部表Oracle
- laravel seed生成測試資料Laravel
- Sql Server生成測試資料SQLServer
- Python做介面測試生成測試報告失敗Python測試報告
- SpringBoot使用外部tomcatSpring BootTomcat
- 【轉】Oracle 外部表Oracle
- 美國借“外部黑客”測試政府網路安全性黑客
- 使用sqlldr載入外部檔案中的資料到Oracle中(轉)SQLOracle
- [轉載]使用uiautomator做UI測試UI
- mysql 動態生成測試資料MySql
- 測試資料之自動生成
- java快速的生成測試資料Java
- allure生成測試報告 0 NAN%測試報告NaN