0% found this document useful (0 votes)
45 views4 pages

Oracle External Tables

This document provides information on Oracle external tables, including how to create external text files, define an internal table representation of the external data, load data from external files into tables, create external tables for writing data to files and reading data from files, define tab delimited external tables, and use external tables to view alert logs. External tables allow data in external files to be queried like regular database tables but do not support insert, update, or delete operations as they are read-only.

Uploaded by

Pedro Pineda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views4 pages

Oracle External Tables

This document provides information on Oracle external tables, including how to create external text files, define an internal table representation of the external data, load data from external files into tables, create external tables for writing data to files and reading data from files, define tab delimited external tables, and use external tables to view alert logs. External tables allow data in external files to be queried like regular database tables but do not support insert, update, or delete operations as they are read-only.

Uploaded by

Pedro Pineda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Oracle External Tables

Version 10.2

Actions As SYS
Data Dictionary user_external_tables
Objects Related To all_external_tables
External Tables dba_external_tables
System Privileges create table
Related To External create any table
Tables drop any table
 
Actions As SYS
Connect / AS SYSDBA
CREATE OR REPLACE DIRECTORY <name> AS
Create Directory <operating_system_path_and_directory>;
CREATE OR REPLACE DIRECTORY ext AS 'c:\external';
GRANT READ ON DIRECTORY <directory_name> TO
Grant Directory <user_id>;
Access To An 
End User GRANT READ ON DIRECTORY ext TO uwclass;
GRANT WRITE ON DIRECTORY ext TO uwclass;
 
External Table
7369,SMITH,CLERK,20
7499,ALLEN,SALESMAN,30
7521,WARD,SALESMAN,30
7566,JONES,MANAGER,20
7654,MARTIN,SALESMAN,30

Save external file as c:\external\demo1.dat


(if UNIX or LINUX use your home directory)
Create Text File
Using a Text Editor
1111,MORGAN,DIRECTOR,10
2222,CLINE,MANAGER,30
3333,HAVEMEYER,VP MKTG,10
4444,LOFSTROM,MANAGER,10
5555,ALLEN,SECURITY,30

Save external file as c:\external\demo2.dat


(if UNIX or LINUX use your home directory)
 
As End User
CREATE TABLE <table_name> (
Create Internal <column_definitions>)
Representation of the
External Table
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY <oracle_directory_object_name>
ACCESS PARAMETERS
(FIELDS TERMINATED BY '<terminator>'
MISSING FIELD VALUES ARE NULL
(<column_name_list>))
LOCATION ('<file_name>'))
[PARALLEL]
REJECT LIMIT <UNLIMITED | integer>;
conn uwclass/uwclass

CREATE TABLE ext_tab (


empno CHAR(4),
ename CHAR(20),
job CHAR(20),
deptno CHAR(2))
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ext
ACCESS PARAMETERS
(FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(empno, ename, job, deptno))
LOCATION ('demo1.dat'))
PARALLEL
REJECT LIMIT 0;

DROP TABLE ext_tab PURGE;

CREATE TABLE ext_tab (


empno CHAR(4),
ename CHAR(20),
job CHAR(20),
deptno CHAR(2))
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ext
ACCESS PARAMETERS
(FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(empno, ename, job, deptno))
LOCATION ('demo1.dat','demo2.dat'))
PARALLEL
REJECT LIMIT 0;
CREATE TABLE <table_name> (
External Table For <column_name, column_name, ...>)
Writing and Reading
ORGANIZATION EXTERNAL
(TYPE oracle_datapump
DEFAULT DIRECTORY <oracle_directory_object_name>
LOCATION ('<file_name'))
[PARALLEL]
AS
<SQL Statement>;
CREATE TABLE ext_write (
tab_name, tblspname, numblocks)
ORGANIZATION EXTERNAL
(TYPE oracle_datapump
DEFAULT DIRECTORY ext
LOCATION ('table_history.exp'))
PARALLEL
AS
SELECT table_name, tablespace_name, blocks
FROM user_tables;

SELECT *
FROM ext_write;

SELECT *
FROM ext_write
WHERE numblocks > 100;

-- open ext_write_####_####.log files


-- open c:\external\table_history.exp
DROP TABLE ext_write;
CREATE TABLE ext_tab (
Tab Delimited empno CHAR(4),
External Table
ename CHAR(20),
job CHAR(20),
deptno CHAR(2))
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ext
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY X'09'
MISSING FIELD VALUES ARE NULL
(empno, ename, job, deptno))
LOCATION ('demo1.dat'))
PARALLEL
REJECT LIMIT 0;
CREATE OR REPLACE DIRECTORY bdump AS
'c:\oracle\product\admin\orabase\bdump\';

CREATE TABLE alert_log (text VARCHAR2(400))


ORGANIZATION EXTERNAL (
TYPE oracle_loader
External Table For DEFAULT DIRECTORY bdump
Viewing Alert Logs ACCESS PARAMETERS (
  RECORDS DELIMITED BY NEWLINE
  NOBADFILE NODISCARDFILE NOLOGFILE)
  location('alert_orabase.log'))
REJECT LIMIT unlimited;

SELECT * FROM system.alert_log;


SELECT *
Query External Table
FROM ext_tab;
 
External tables are READ ONLY. Insert, update, and delete
NOTE:
can not be performed.

Related Topics
Tables

You might also like