1. Understand oracle External tables
External table definition: The structure is stored in the data dictionary, and the table data is stored in the OS file.
Purpose: query the OS file data in the database and load the OS file data to the database.
Differences from other tables: you cannot perform DML operations on External tables, nor create indexes on External tables. You can only perform select operations.
2. Create a simple External table 1. Create an OS file
Because external tables are mainly used to view files on the OS, a file is first created on the OS.
Mkdir-p/oracle/ext
Vi/oracle/ext. dat
10, 20, 30
40, 50, 60
70, 80, 90
2. Grant user permissions and create directory objects
Create a new user
Create user test identified by "123" defaultTablespaceTest quota unlimited on test; |
User authorization
SQL> grant create any directory to test; |
Create a directory object
SQL & gt; conn test/123 Connected. SQL> create directory ext as '/oracle/ext '; Directory created. |
3. Create an External table
SQL> createTableExttable (
Id number, name varchar2 (10), I number
) Organization external
(Type oracle_loader
Default directory ext
AccessParameters
(Records delimited by newline
Fields terminated ','
) Location ('ext. dat ')
);
4. Test
SQL> select * from exttable; ID NAME I ------------------------------ 10 20 30 40 50 60 708090 |
The test is successful. You can view the OS file data in the database.