As a table type of oracle, external tables are not as convenient to use as ordinary database tables, but sometimes they can bring great convenience during data migration or data loading. Sometimes it is more convenient than loading data with sql*loader. For convenience, the commands and operations for creating and applying external tables are recorded as follows:
--Create a directory object to store files
sqlplus username/passwd@prod
create directory ex_data as '/home/ex_data/';
-- create external table
CREATE TABLE tab1_ex
(
C1 VARCHAR2(32 BYTE),
C2 VARCHAR2(64 BYTE),
C3 VARCHAR2(32 BYTE),
C4 VARCHAR2(255 BYTE),
C5 VARCHAR2(128 BYTE),
C6 VARCHAR2(36 BYTE),
C7 VARCHAR2(64 BYTE),
C8 VARCHAR2(128 BYTE),
C9 VARCHAR2(64 BYTE),
C10 VARCHAR2(64 BYTE),
C11 VARCHAR2(8 BYTE),
C12 VARCHAR2(8 BYTE),
C13 VARCHAR2(8 BYTE),
C14 VARCHAR2(8 BYTE),
C15 VARCHAR2(8 BYTE),
C16 VARCHAR2(8 BYTE),
C17 VARCHAR2(8 BYTE),
C18 VARCHAR2(8 BYTE),
C19 VARCHAR2(8 BYTE),
C20 VARCHAR2(32 BYTE),
C21 VARCHAR2(8 BYTE),
C22 VARCHAR2(8 BYTE)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY ex_data
ACCESS PARAMETERS
( records delimited by newline
fields terminated by '|'
)
LOCATION (ex_data:'tab1_ex.txt')
);
--Apply external table
select count(*) from tab1_ex;
--Note:
1. Although external tables can be queried like ordinary database tables, indexes cannot be built on your columns above;
2. It is also not possible to insert data into an external table;
3. It is also not possible to update and delete the data in the external table;