資料庫表--external table
解除安裝表資料到檔案並重新讀取
建立目錄
JEL@JEL >create directory dir_dmp as '/home/oracle';
Directory created.
JEL@JEL >grant read,write on directory dir_dmp to public;
Grant succeeded.
解除安裝資料
JEL@JEL >select * from test;
X Y
---------- ----------
1 1
2 2
3 3
JEL@JEL >create table t1 organization external (type oracle_datapump default directory dir_dmp
2 location ('t1_1.dat','t1_2.dat')) parallel 2 as select * from test;
Table created.
JEL@JEL >select * from t1;
X Y
---------- ----------
1 1
2 2
3 3
[oracle@jel ~]$ pwd
/home/oracle
[oracle@jel ~]$ ls
t1_2.dat t1_1.dat temp
透過strings可以檢視檔案內容
載入資料
JEL@JEL >create table t2 (x int,y int) organization external (type oracle_datapump default directory dir_dmp location ('t1_1.dat','t1_2.dat'));
Table created.
JEL@JEL >select * from t2;
X Y
---------- ----------
1 1
2 2
3 3
使用SQL*loader建立外部表
建立資料檔案,控制檔案
t.dat
1,1,1,1,1,
2,2,2,2,2,
3,3,
a,a,a,
#####################
t.ctl
load data
infile '/home/oracle/t.dat'
badfile '/home/oracle/t.bad'
discardfile '/home/oracle/t.dsc'
append
into table jel.t3
fields terminated by ',' optionally enclosed by '"'
trailing nullcols
(x1,x2,x3,x4,x5)
################################
建立表
JEL@JEL >create table t3 (x1 int,x2 int,x3 int,x4 int,x5 int);
Table created.
匯入
[oracle@jel ~]$ sqlldr userid=jel/jel control=/home/oracle/t.ctl external_table=generate_only log=/home/oracle/t.log
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Dec 12 12:17:20 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
[oracle@jel ~]$ more t.log
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Dec 12 12:17:20 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: /home/oracle/t.ctl
Data File: /home/oracle/t.dat
Bad File: /home/oracle/t.bad
Discard File: /home/oracle/t.dsc
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation: none specified
Path used: External Table
Table JEL.T3, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
X1 FIRST * , O(") CHARACTER
X2 NEXT * , O(") CHARACTER
X3 NEXT * , O(") CHARACTER
X4 NEXT * , O(") CHARACTER
X5 NEXT * , O(") CHARACTER
CREATE DIRECTORY statements needed for files
------------------------------------------------------------------------
CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS '/home/oracle/'---------與下面對應
CREATE TABLE statement for external table:
------------------------------------------------------------------------
CREATE TABLE "SYS_SQLLDR_X_EXT_T3" ---------------修改成要建立的使用者的對應表名
(
"X1" NUMBER(38),
"X2" NUMBER(38),
"X3" NUMBER(38),
"X4" NUMBER(38),
"X5" NUMBER(38)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 ----------與上面對應
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.bad'
DISCARDFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.dsc'
LOGFILE 't.log_xt' --------------去掉絕對路徑
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
"X1" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X2" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X3" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X4" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X5" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
)
)
location
(
't.dat'
)
)REJECT LIMIT UNLIMITED
INSERT statements used to load internal tables:
------------------------------------------------------------------------
INSERT /*+ append */ INTO JEL.T3
(
X1,
X2,
X3,
X4,
X5
)
SELECT
"X1",
"X2",
"X3",
"X4",
"X5"
FROM "SYS_SQLLDR_X_EXT_T3"
statements to cleanup objects created by previous statements:
------------------------------------------------------------------------
DROP TABLE "SYS_SQLLDR_X_EXT_T3"
DROP DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
Run began on Thu Dec 12 12:17:20 2013
Run ended on Thu Dec 12 12:17:20 2013
Elapsed time was: 00:00:00.11
CPU time was: 00:00:00.02
建立外部表
JEL@JEL >CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS '/home/oracle/';
JEL@JEL >CREATE TABLE sqlldr_external
(
"X1" NUMBER(38),
"X2" NUMBER(38),
"X3" NUMBER(38),
"X4" NUMBER(38),
"X5" NUMBER(38)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.bad'
DISCARDFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.dsc'
LOGFILE 't.log_xt'
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
"X1" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X2" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X3" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X4" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X5" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
)
)
location
(
't.dat'
)
)REJECT LIMIT UNLIMITED;
JEL@JEL >select *from sqlldr_external;
X1 X2 X3 X4 X5
---------- ---------- ---------- ---------- ----------
1 1 1 1 1
2 2 2 2 2
3 3
此處,沒有載入資料檔案中的最後一行,是因為型別不正確,被放到了t.bad檔案中
[oracle@jel ~]$ more t.bad
a,a,a,
建立目錄
JEL@JEL >create directory dir_dmp as '/home/oracle';
Directory created.
JEL@JEL >grant read,write on directory dir_dmp to public;
Grant succeeded.
解除安裝資料
JEL@JEL >select * from test;
X Y
---------- ----------
1 1
2 2
3 3
JEL@JEL >create table t1 organization external (type oracle_datapump default directory dir_dmp
2 location ('t1_1.dat','t1_2.dat')) parallel 2 as select * from test;
Table created.
JEL@JEL >select * from t1;
X Y
---------- ----------
1 1
2 2
3 3
[oracle@jel ~]$ pwd
/home/oracle
[oracle@jel ~]$ ls
t1_2.dat t1_1.dat temp
透過strings可以檢視檔案內容
載入資料
JEL@JEL >create table t2 (x int,y int) organization external (type oracle_datapump default directory dir_dmp location ('t1_1.dat','t1_2.dat'));
Table created.
JEL@JEL >select * from t2;
X Y
---------- ----------
1 1
2 2
3 3
使用SQL*loader建立外部表
建立資料檔案,控制檔案
t.dat
1,1,1,1,1,
2,2,2,2,2,
3,3,
a,a,a,
#####################
t.ctl
load data
infile '/home/oracle/t.dat'
badfile '/home/oracle/t.bad'
discardfile '/home/oracle/t.dsc'
append
into table jel.t3
fields terminated by ',' optionally enclosed by '"'
trailing nullcols
(x1,x2,x3,x4,x5)
################################
建立表
JEL@JEL >create table t3 (x1 int,x2 int,x3 int,x4 int,x5 int);
Table created.
匯入
[oracle@jel ~]$ sqlldr userid=jel/jel control=/home/oracle/t.ctl external_table=generate_only log=/home/oracle/t.log
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Dec 12 12:17:20 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
[oracle@jel ~]$ more t.log
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Dec 12 12:17:20 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: /home/oracle/t.ctl
Data File: /home/oracle/t.dat
Bad File: /home/oracle/t.bad
Discard File: /home/oracle/t.dsc
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation: none specified
Path used: External Table
Table JEL.T3, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
X1 FIRST * , O(") CHARACTER
X2 NEXT * , O(") CHARACTER
X3 NEXT * , O(") CHARACTER
X4 NEXT * , O(") CHARACTER
X5 NEXT * , O(") CHARACTER
CREATE DIRECTORY statements needed for files
------------------------------------------------------------------------
CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS '/home/oracle/'---------與下面對應
CREATE TABLE statement for external table:
------------------------------------------------------------------------
CREATE TABLE "SYS_SQLLDR_X_EXT_T3" ---------------修改成要建立的使用者的對應表名
(
"X1" NUMBER(38),
"X2" NUMBER(38),
"X3" NUMBER(38),
"X4" NUMBER(38),
"X5" NUMBER(38)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 ----------與上面對應
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.bad'
DISCARDFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.dsc'
LOGFILE 't.log_xt' --------------去掉絕對路徑
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
"X1" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X2" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X3" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X4" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X5" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
)
)
location
(
't.dat'
)
)REJECT LIMIT UNLIMITED
INSERT statements used to load internal tables:
------------------------------------------------------------------------
INSERT /*+ append */ INTO JEL.T3
(
X1,
X2,
X3,
X4,
X5
)
SELECT
"X1",
"X2",
"X3",
"X4",
"X5"
FROM "SYS_SQLLDR_X_EXT_T3"
statements to cleanup objects created by previous statements:
------------------------------------------------------------------------
DROP TABLE "SYS_SQLLDR_X_EXT_T3"
DROP DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
Run began on Thu Dec 12 12:17:20 2013
Run ended on Thu Dec 12 12:17:20 2013
Elapsed time was: 00:00:00.11
CPU time was: 00:00:00.02
建立外部表
JEL@JEL >CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS '/home/oracle/';
JEL@JEL >CREATE TABLE sqlldr_external
(
"X1" NUMBER(38),
"X2" NUMBER(38),
"X3" NUMBER(38),
"X4" NUMBER(38),
"X5" NUMBER(38)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.bad'
DISCARDFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'t.dsc'
LOGFILE 't.log_xt'
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
"X1" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X2" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X3" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X4" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
"X5" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
)
)
location
(
't.dat'
)
)REJECT LIMIT UNLIMITED;
JEL@JEL >select *from sqlldr_external;
X1 X2 X3 X4 X5
---------- ---------- ---------- ---------- ----------
1 1 1 1 1
2 2 2 2 2
3 3
此處,沒有載入資料檔案中的最後一行,是因為型別不正確,被放到了t.bad檔案中
[oracle@jel ~]$ more t.bad
a,a,a,
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29337971/viewspace-1063061/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Redshift建立外部架構external schema和外部表external table架構
- use azure data studio to create external table for oracleOracle
- GaussDB資料庫SQL系列-LOCK TABLE資料庫SQL
- 有關oracle external table的一點測試。Oracle
- 資料庫 sqlite3_get_table,sqlite3_free_table資料庫SQLite
- 【資料庫資料恢復】Oracle資料庫誤truncate table的資料恢復案例資料庫資料恢復Oracle
- 【資料庫資料恢復】誤truncate table的Oracle資料庫資料恢復方案資料庫資料恢復Oracle
- 【資料庫資料恢復】oracle資料庫誤truncate table怎麼恢復資料?資料庫資料恢復Oracle
- mybatis進行資料庫建表 CREATE command denied to user 'root'@'127.0.0.1' for table 問題MyBatis資料庫127.0.0.1
- vxe-form table 表單使用資料校驗ORM
- javascript: 帶分組資料的Table表頭排序JavaScript排序
- 建立資料庫表資料庫
- 調研azkaban內部資料庫幾張table資料庫
- PostgreSQL:表空間-->資料庫-->表SQL資料庫
- phpMyAdmin管理資料庫和資料表PHP資料庫
- 資料庫 建立 3表資料庫
- django資料庫同步時報錯“Table 'XXX' already exists”Django資料庫
- 資料庫 Table is marked as crashed and should be repaired 解決辦法資料庫AI
- ABAP資料庫表的後設資料資料庫
- 資料庫怎麼分庫分表資料庫
- MySQL資料庫之分庫分表方案MySql資料庫
- 【資料庫資料恢復】如何恢復Oracle資料庫truncate表的資料資料庫資料恢復Oracle
- 【TABLE】Oracle表資訊收集指令碼Oracle指令碼
- SQL建立資料庫和表SQL資料庫
- 資料庫表初始化資料庫
- 資料庫 表單運用資料庫
- Oracle資料庫表碎片整理Oracle資料庫
- 分庫分表插入資料
- Oracle資料庫管理——表資料庫高水位及shrink操作Oracle資料庫
- 大資料資料庫讀寫分離分庫分表大資料資料庫
- Lua table(表)
- 【北亞資料恢復】oracle資料庫執行truncate table命令怎麼恢復資料?資料恢復Oracle資料庫
- 查詢資料庫表及表欄位資料庫
- 資料庫分庫分表的總結資料庫
- 客快物流大資料專案(五十一):資料庫表分析 物流專案 資料庫表設計大資料資料庫
- 【資料結構與演算法學習】雜湊表(Hash Table,雜湊表)資料結構演算法
- 織夢資料庫表結構_Dedecms資料庫表和欄位詳細介紹資料庫
- Oracle 資料庫整理表碎片Oracle資料庫
- 報表資料分庫儲存