天天看點

oracle 建立外部表,Oracle 10g成功建立外部表詳解

1. 建立兩個外部檔案分别為1.txt,2.txt其中分别隻有一條資料。

2.建立一個邏輯目錄并進行适當授權:

SQL>create directory ztj1_dir as 'c:\ztj1\';

目錄已建立

然後在實體路徑上手工建立實際的目錄,如:在c:\盤下建立ztj目錄檔案夾。

SQL>grant read on directory ztj1_dir to scott

授權成功

SQL>grant write on directory ztj1_dir to scott

授權成功

注意:建立完畢邏輯目錄之後把平面檔案拷貝到該目錄下,另外還要注意檔案名字不要寫錯,如:把前面建立的外部檔案1.txt,2.txt分别移動到手工建立的目錄下面(c:\ztj)

3.建立外部表

SQL>ED

編輯已寫入的檔案

create table demo(

emp_id number(4),

ename varchar2(12),

job varchar2(12),

mgr_id number(4),

salary number(8),

comm number(8),

dept_id number(2)

)

organization external

(

type Oracle_loader

default directory ztj1_dir

access parameters(records delimited by newline

skip=1 //跳過第一行,如果第一行不是标題,不用加這個參數

fields terminated by ",")

location('1.txt','2.txt','3.txt')

)

SQL>/

表已建立

4.進行select選擇操作看看是否正确

SQL>select * from demo;

如果要得到外部表的有關資訊:

SQL>select owner,table_name,default_directory_name,access_parameters from dba_external_tables;

如果DBA想要知道平面檔案的位置,使用如下的查詢:

SQL>select* from DBA_EXTERNAL_LOCATIONS;

步驟下載下傳位址:

具體下載下傳目錄在 /2013年資料/1月/11日/Oracle 10g成功建立外部表詳解

oracle 建立外部表,Oracle 10g成功建立外部表詳解