- 以system或其他管理员登录
- 创建Oracle管控目录
CREATE DIRECTORY hc_name_data_dir AS 'c:/ora/external/hc_name/';
CREATE DIRECTORY hc_name_log_dir AS 'c:/ora/external/hc_name/'; - 确认
SELECT * FROM dba_directories WHERE directory_name like '%HC%'; - 授予目录相应权限给需要创建外部表的用户
GRANT WRITE ON DIRECTORY hc_name_log_dir TO scott;
GRANT READ ON DIRECTORY hc_name_data_dir TO scott; - 确认
SELECT * FROM dba_tab_privs WHERE table_name like '%_DIR' AND grantee = 'SCOTT'; - 以该用户身份登录,如例中的scott
- 创建外部管理表
CREATE TABLE name(id number(6), firstname VARCHAR2(100), surname VARCHAR(36)) ORGANIZATION EXTERNAL(TYPE oracle_loader DEFAULT DIRECTORY HC_NAME_DATA_DIR ACCESS PARAMETERS(RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII BADFILE 'HC_NAME_LOG_DIR' : 'name.bad' LOGFILE 'HC_NAME_LOG_DIR' : 'name.log' FIELDS TERMINATED BY " " OPTIONALLY ENCLOSED BY '/t') LOCATION ('name.txt')) REJECT LIMIT UNLIMITED; - 确认
SELECT table_name, default_directory_owner, default_directory_name FROM user_external_tables;
注意外部管理表只可读,且不归属于任何表空间.