You are on page 1of 4

External Tables

External Data is exposed like Data residing in


a regular Oracle table
– meta data definition via DDL command
– directly accessible inside the database, e.g. with
SQL, PL/SQL, Java
– no temporary staging necessary
– intra-file parallelism eliminates need for manual
split of input file
Transparent Usage of External Tables within
SQL*Loader
External Data is read only
External Tables
Benefits
Especially useful for
– ‘Describe it once, deploy it often’
– Scaling transparent intra-file parallelism without the
necessity to split input source
– Pipelining external data directly from the loading
into the transformation phase
Simplified Usage versus SQL*Loader
– Security control for external data inside the RDBMS
– No explicit OS access necessary
External Tables
Setup
Creation of Table Meta Data Oracle Server
– enhanced DDL command
CREATE TABLE PRODUCTS_EXT;

PRODUCTS_EXT
10, Sweater, .., 22.00, 5.00
PROD_ID PROD_NAME ... PRICE DISCOUNT
20, Skirt, ... ,25.50, 8.50
30, Trousers, …,50.00, 9.00 10 Sweater 22.00 5.00
20 Skirt 25.50 8.50
40, ... 30 Trousers 50.00 9.00
...

Use it
– Access with SQL, PL/SQL SELECT .. FROM
and Java PRODUCTS_EXT;
External Tables
Example
CREATE TABLE products_ext
( prod_id NUMBER, prod_name VARCHAR2(50), ... ,
price NUMBER(6,2), discount NUMBER(6,2) )
ORGANIZATION EXTERNAL -- declares table as external table
( TYPE loader_type -- access type of external table
DEFAULT DIRECTORY stage_dir --parameters similar to SQL*Loader
ACCESS PARAMETERS
( <records, fields similar to SQL*Loader>,
BADFILE ‘bad_products_ext’,
LOGFILE ‘log_products_ext’,
LOCATION (‘new_prod1.txt’, ‘ new_prod2.txt’)) -- two input files
PARALLEL 5 -- default degree of parallelism of 5
REJECT LIMIT 200;

INSERT /*+ APPEND */ INTO products


SELECT prod_id, prod_name, .., price as prod_list_price,
(price - discount) as min_price -- SQL calculation
FROM products_ext;

You might also like