什麼是外部表?
External table和正規的表很相似
>創建的語法類似於
>數據在數據庫的外部組織
>操作系統文件在數據庫中的標志是通過一個邏輯目錄來映射的
>數據是只讀的
>不可以在上面運行任何DML操作
>可以查詢操作和連接
例子
假定有如下的兩個數據文件
假設如下的兩個平面文件
Code: [Copy to clipboard]
Code: [Copy to clipboard]
(要有對操作系統中該目錄的讀寫權限
Code: [Copy to clipboard]
SQL> CREATE DIRECTORY TESTDIR AS
目錄已創建
SQL> GRANT READ ON DIRECTORY TESTDIR TO DEMO;
授權成功
SQL> GRANT WRITE ON DIRECTORY TESTDIR TO DEMO;
授權成功
注意
Code: [Copy to clipboard]
SQL> ED
已寫入文件 afiedt
SQL> /
表已創建
Code: [Copy to clipboard]
SQL> select * from DEMO
EMP_ID ENAME JOB MGR_ID HIREDATE SALARY COMM DEPT_ID
如果要得到外部表的有關信息
Code: [Copy to clipboard]
SQL> DESC DBA_EXTERNAL_TABLES;
名稱
OWNER
TABLE_NAME
TYPE_OWNER
TYPE_NAME
DEFAULT_DIRECTORY_OWNER
DEFAULT_DIRECTORY_NAME
REJECT_LIMIT
ACCESS_TYPE
ACCESS_PARAMETERS
SQL> SELECT OWNER
OWNER TABLE_NAME DEFAULT_DIRECTORY_NAME ACCESS_PARAMETERS
DEMO EXT TESTDIR RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY
如果DBA想要知道平面文件的位置
Code: [Copy to clipboard]
SQL> desc DBA_EXTERNAL_LOCATIONS;
名稱
OWNER
TABLE_NAME
LOCATION
DIRECTORY_OWNER
DIRECTORY_NAME
SQL> select * from DBA_EXTERNAL_LOCATIONS;
OWNER TABLE_NAME LOCATION DIR DIRECTORY_NAME
DEMO EXT
DEMO EXT
From:http://tw.wingwit.com/Article/program/Oracle/201311/16715.html