Free Newsletters:
Database Journal  
DBAnews  

DBASupport

 The Knowledge Center for Oracle Professionals

Search DBAsupport:
 
HOME 11g Central 10g Central 9i Central 8i Central Oracle News Scripts FAQ OCP Zone Resources Technical Docs Tools & Utilities Forums
internet.com

» HOME
» FEATURES
    11g Central
    10g Central
    9i Central
    8i Central
    Oracle News
» COMMUNITY
    Scripts
    Forums
    FAQ
    OCP Zone
» RESOURCES
    Resources
    Technical Docs
    Tools & Utilities
    Tech Jobs


internet.commerce
Be a Commerce Partner
Shop
Holiday Gift Ideas
Promotional Golf
Server Racks
Promote Your Website
Domain registration
KVM Switches
Memory Upgrades
GPS Devices
Cell Phones


internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


   DBAsupport.com > Oracle > Oracle 9i Central > Featured Stories


Guide to Oracle 11g and Database Migration
Oracle Database 11g includes more features for self-management and automation, which makes it easier for customers to cost-effectively manage their data. Download this Internet.com eBook for an overview of some of the new features in 11g and for an overview of the issues you need to consider as you prepare for a database migration. »
Innovate Faster with Oracle Database 11g
Read this in-depth analysis of 56 customers, which shows significant differences between the value software vendors Oracle and SAP deliver to midsize companies. »
Oracle Business Intelligence Standard Edition One
Find out how Newport Beach, CA-based Mobilitie is shaking up the telecom industry by leveraging technology to provide an entirely different financial model for deploying, upgrading, and owning wireless and wireline network assets. »
Business Intelligence and Enterprise Performance Management: Trends for Emerging Businesses
Quickly implementing an ERP software solution can be of tremendous benefit; however, companies often struggle to balance the benefits of reducing implementation time and cost with the risks of an accelerated deployment. Read this white paper to learn about easy-to-follow best practices for achieving a successful accelerated implementation. »
Making the Case for Oracle Database on Windows
Users benefit as vendors reduce enterprise complexity and deliver integration. »


CA ERwin® Data Modeler Proven database design and modeling. Efficiently analyze, design and deploy effective database solutions. Whitepaper: Manage SQL Server Deployments
Try it free: CA ERwin® Data Modeler

ASP 3.0/.NET Developer
Jupitermedia
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

External Tables in Oracle 9i
Ajay Gursahani, ajay.gursahani@mahindrabt.com


This article gives a brief understanding about External tables. External Tables are defined as tables that do not reside in the database, and can be in any format for which an access driver is provided. This external table definition can be thought of as a view that allows running any SQL query against external data without requiring that the external data first be loaded into the database.

You can, for example, select, join, or sort external table data. You can also create views and synonyms for external tables. However, no DML operations (UPDATE, INSERT, or DELETE) are possible, and indexes cannot be created on external tables.

Oracle provides the means of defining the metadata for external tables through the CREATE TABLE ... ORGANIZATION EXTERNAL statement.

Before firing the above command we need to create a directory object where the external files will reside.

CREATE OR REPLACE DIRECTORY EXT_TABLES AS 'C:\EXT_TABLES\';

Example: The example below describes how to create external files, create external tables, query external tables and create views.

Step I: Creating the flat files, which will be queried

The file "emp_ext1.dat" contains the following sample data:

101,Andy,FINANCE,15-DEC-1995
102,Jack,HRD,01-MAY-1996
103,Rob,DEVELOPMENT,01-JUN-1996
104,Joe,DEVELOPMENT,01-JUN-1996

The file "emp_ext2.dat" contains the following sample data:

105,Maggie,FINANCE,15-DEC-1997
106,Russell,HRD,01-MAY-1998
107,Katie,DEVELOPMENT,01-JUN-1998
108,Jay,DEVELOPMENT,01-JUN-1998

Copy these files under "C:\EXT_TABLES"

Step II: Create a Directory Object where the flat files will reside

SQL> CREATE OR REPLACE DIRECTORY EXT_TABLES AS 'C:\EXT_TABLES';

Directory created.

Step III: Create metadata for the external table

SQL> CREATE TABLE emp_ext
	(
	empcode NUMBER(4), 
	empname VARCHAR2(25),
	deptname VARCHAR2(25),
	hiredate date
	)
  ORGANIZATION EXTERNAL
    (
      TYPE ORACLE_LOADER
      DEFAULT DIRECTORY ext_tables
      ACCESS PARAMETERS
      (
        RECORDS DELIMITED BY NEWLINE
        FIELDS TERMINATED BY ','
        MISSING FIELD VALUES ARE NULL
      )
      LOCATION ('emp_ext1.dat','emp_ext2.dat')
    )
  REJECT LIMIT UNLIMITED;

Table created.

The REJECT LIMIT clause specifies that there is no limit on the number of errors that can occur during a query of the external data.

"The ORACLE_LOADER is an access driver for loading data from the external files into the tables."

Step IV: Querying Data

SQL> SELECT * FROM  emp_ext;

        EMPCODE	 EMPNAME              DEPTNAME               HIREDATE
       --------- ------------------- ---------------------- ---------
         101 Andy                       FINANCE                15-DEC-95
         102 Jack                       HRD                    01-MAY-96
         103 Rob                        DEVELOPMENT            01-JUN-96
         104 Joe                        DEVELOPMENT            01-JUN-96
         105 Maggie                     FINANCE                15-DEC-97
         106 Russell                    HRD                    01-MAY-98
         107 Katie                      DEVELOPMENT            01-JUN-98
         108 Jay                        DEVELOPMENT            01-JUN-98

8 rows selected.

Step V: Creating Views

SQL> CREATE VIEW v_empext_dev AS
		SELECT * FROM emp_ext
		WHERE deptname='DEVELOPMENT';
View created.

SQL> SELECT * FROM v_empext_dev;

         EMPCODE EMPNAME            DEPTNAME             HIREDATE
       ------------ ------------- ---------------------- ---------
         103 Rob                     DEVELOPMENT       01-JUN-96
         104 Joe                     DEVELOPMENT       01-JUN-96
         107 Katie                   DEVELOPMENT       01-JUN-98
         108 Jay                     DEVELOPMENT       01-JUN-98

You can get the information of the objects you have created through DBA_OBJECTS, ALL_OBJECTS or USER_OBJECTS.

SQL> 	SELECT OBJECT_NAME, OBJECT_TYPE FROM ALL_OBJECTS
WHERE OBJECT_NAME LIKE 'EMP_EXT';

OBJECT_NAME                 OBJECT_TYPE
---------------------- 	------------------
EMP_EXT		          TABLE

1 row selected.

SQL> 	SELECT OBJECT_NAME, OBJECT_TYPE FROM ALL_OBJECTS
WHERE OBJECT_NAME LIKE 'EXT_TABLES';

OBJECT_NAME                 OBJECT_TYPE
---------------------- 	------------------
EXT_TABLES                  DIRECTORY

1 row selected.

Populating Tables using the INSERT command

You can populate data from external files using an "insert into … select from" statement instead of using SQL*Loader. This method provides very fast data loads.

Example:

Consider a table EMPLOYEES:

SQL> desc EMPLOYEES;

 Name                              Null?    	Type
 --------------------------------- -------- 	--------------

 EMPCODE                                       NUMBER(4)
 EMPNAME                                       VARCHAR2(25)
 DEPTNAME                                      VARCHAR2(25)
 HIREDATE                                      DATE

SQL> INSERT INTO employees 
     (empcode,empname,deptname,hiredate) SELECT * FROM emp_ext;

8 rows created.

SQL> SELECT * FROM employees;

        EMPCODE 	EMPNAME               DEPTNAME               HIREDATE
       ------------ ------------------- ---------------------- ---------
         101 Andy                        FINANCE                 15-DEC-95
         102 Jack                        HRD                     01-MAY-96
         103 Rob                         DEVELOPMENT             01-JUN-96
         104 Joe                         DEVELOPMENT             01-JUN-96
         105 Maggie                      FINANCE                 15-DEC-97
         106 Russell                     HRD                     01-MAY-98
         107 Katie                       DEVELOPMENT             01-JUN-98
         108 Jay                         DEVELOPMENT             01-JUN-98

8 rows selected.

Dropping External Tables

For an external table, the DROP TABLE statement removes only the table metadata in the database. It has no affect on the actual data, which resides outside of the database.

Summary

The external files are thus tables in the data dictionary, which can be queried as you would query ordinary Oracle tables. You can perform fast data loads using the above method instead of using SQL*Loader.


Back to DBAsupport.com







JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES