假設,你需要將某個路徑下的全部檔案txt檔案匯入資料庫,並保留對應的檔名。外部檔案中lob欄位的位置,應該存放檔名。
在資料庫中:$ for n in
`ls *.txt`;do
echo
"$n|$n"
;done
> test_load.txt # "|"兩邊不要留空,否則外部表讀取檔案時會報錯,說找不到該檔案
$ cat test.txt
q10_d.txt|q10_d.txt
q11_d.txt|q11_d.txt
q12_d.txt|q12_d.txt
$ pwd
/home/oracle/test_files
注意:--建立所需路徑
create
orreplace directory sql_log as
'/home/oracle/ext_log'
;create
orreplace directory sql_dir as
'/home/oracle/test_files'
;--建立外部表
drop
table et_text_tab;
create
table et_text_tab(
file_name varchar2(
100)
, file_content clob
)organization external(
type oracle_loader
default directory sql_dir
access parameters
( records delimited by newline
badfile sql_log : 'textload_%a_%p.bad'
logfile sql_log : 'textload_%a_%p.log'
fields
terminated
by'|' missing field values are null
( file_name char
(100),
clob_filename char
(100))
column transforms (file_content from lobfile(clob_filename)
from
(sql_dir)clob)
) location(
'test_load.txt'))
reject limit unlimited
/--匯入資料
alter
session
enable parallel dml;
--使用並行執行
alter
table text_tab parallel 4
;--設定並行度為4
insert
into text_tab(
file_name,
file_content
)select file_name,file_content
from et_text_tab;
commit
;
參看閱讀:external tables containing lob data
oracle外部表的使用 使用外部表
oracle外部表的使用 該執行緒包含一些使用外部表的有用技巧。使用外部表 1.將表指向外部檔案。如果外部檔案中的資料被更改,則表中的資料也將發生變化。2.外部表可以按照與聯接,檢視中的標準表相同的方式進行查詢.並可以使用外部表上的所有型別的功能。3.獲取有關外部表的資訊,查詢 user exter...
oracle 使用sqlload匯入外部資料
使用sqlload大批量匯入資料 第一步 建立表 create table testht demo id varchar2 20 byte not null enable,name varchar2 20 byte age varchar2 20 byte 建立控制檔案 home demo.ctl ...
oracle 外部表使用詳解
外部表,相對於資料庫內部表來說的,意思是將作業系統檔案作為乙個資料庫,資料從檔案而來。我把它理解成類似指標的東西,告訴使用者,這個表的資料是從哪些檔案來的。語法如下 create table table1 id varchar2 4 name varchar2 20 organization ext...