Oracle External Tables Gwendolyn Wright 11/07/02
Agenda Introduction Dictionary Objects and External Tables Creating an External Table Querying External Tables External Tables – Fixed Records Data Dictionary Views for External Tables Creating External Table Scripts External Table Advantages External Table Disadvantages Possible Issues Where to Get More Information
Introduction External tables are read-only tables that are defined in flat-files outside of the database but can be accessed by SQL inside of the database.  This feature can be used to load data into a database from flat files without using SQL*Loader.
Directory Objects and External tables Create a directory and grant read on the directory to a user. These tables are like regular SQL tables with some exceptions: - The metadata of external tables is created using the SQL “CREATE TABLE … ORGANIZATION EXTERNAL” statement. - The data resides outside the database in OS files, thus the EXTERNAL organization. - The OS files are identified inside the database through a logical directory defining the OS physical directory where they are located. - The data is read only. - You cannot perform any DML operations, nor create indexes. - The external table can be queried and joined directly, in parallel using the SQL statement SELECT.
Creating an External Table Create a flat file emp1.dat & emp2.dat Create a directory that defines the location of the directory where the flat files reside on the OS Create the external table (metadata) Select data from the external table to verify that data are visible
Querying External Tables External tables can be queried just like any other table.
External Tables – Fixed Records In addition to loading records with a variable format, we can also load them with a fixed format.
Data Dictionary Views for External Tables To get external tables names and characteristics, the DBA_EXTERNAL_TABLES view can be queried. If you need to retrieve the locations of the flat files, the view is DBA_EXTERNAL_LOCATIONS.
Creating External Table Scripts This is a new SQL*Loader option EXTERNAL_TABLE that can be used to create external tables as follows: - Create a sample data file for the external table - Create a SQL*Loader control script. - Run SQL*Loader using the control script to generate the commands for building an external table. - View the SQL*Loader log file.
External Tables Advantages The  EXTERNAL_TABLE command-line parameter: NOT USED  – This is the default value.  In this case, the load is done using conventional or direct path mode. GENERATE ONLY  – The load job is not performed.  Instead, all of the SQL statements to be executed for the whole load job are written to the specified SQL*Loader log file.  The load can be done later by executing the statements in the log file EXECUTE  – The load job is performed using external tables by executing SQL statements.  If any of the statements fail and return an error, the attempt to load stops.  Statements are always placed in the lof gile except the directory statements as they are executed. If the EXECUTE or GENERATE_ONLY option is specified, the userid that loads should be granted the following privileges: CREATE ANY DIRECTORY DROP ANY DIRECTORY
External Table Disadvantages In an external table load for which the data file character set is UTF8 or UTF16, it is not possible to suppress checking for byte-order marks.  The suppression is only necessary if the beginning of the data file contains binary data that matches the byte-order mark encloding.  It is possibel to suppress byte-order mark checking with usual loads.
Possible Issues Ownership of the External Tables
Where to Get More Information Oracle9i Recovering Lost Data  – Oracle Metalink – Doc 174425.1 Parameters FLASHBACK_SCN & FLASHBACK_TIME:   Point in Time Export – Oracle Metalink – Doc 204334.1 Flashback Query:  Confusion on SCN based  – Oracle Metalink –  Doc 302681.999 Oracle 9i New Features Flashback  – Oracle Metalink – Doc 143217.1

Oracle External Tables

  • 1.
    Oracle External TablesGwendolyn Wright 11/07/02
  • 2.
    Agenda Introduction DictionaryObjects and External Tables Creating an External Table Querying External Tables External Tables – Fixed Records Data Dictionary Views for External Tables Creating External Table Scripts External Table Advantages External Table Disadvantages Possible Issues Where to Get More Information
  • 3.
    Introduction External tablesare read-only tables that are defined in flat-files outside of the database but can be accessed by SQL inside of the database. This feature can be used to load data into a database from flat files without using SQL*Loader.
  • 4.
    Directory Objects andExternal tables Create a directory and grant read on the directory to a user. These tables are like regular SQL tables with some exceptions: - The metadata of external tables is created using the SQL “CREATE TABLE … ORGANIZATION EXTERNAL” statement. - The data resides outside the database in OS files, thus the EXTERNAL organization. - The OS files are identified inside the database through a logical directory defining the OS physical directory where they are located. - The data is read only. - You cannot perform any DML operations, nor create indexes. - The external table can be queried and joined directly, in parallel using the SQL statement SELECT.
  • 5.
    Creating an ExternalTable Create a flat file emp1.dat & emp2.dat Create a directory that defines the location of the directory where the flat files reside on the OS Create the external table (metadata) Select data from the external table to verify that data are visible
  • 6.
    Querying External TablesExternal tables can be queried just like any other table.
  • 7.
    External Tables –Fixed Records In addition to loading records with a variable format, we can also load them with a fixed format.
  • 8.
    Data Dictionary Viewsfor External Tables To get external tables names and characteristics, the DBA_EXTERNAL_TABLES view can be queried. If you need to retrieve the locations of the flat files, the view is DBA_EXTERNAL_LOCATIONS.
  • 9.
    Creating External TableScripts This is a new SQL*Loader option EXTERNAL_TABLE that can be used to create external tables as follows: - Create a sample data file for the external table - Create a SQL*Loader control script. - Run SQL*Loader using the control script to generate the commands for building an external table. - View the SQL*Loader log file.
  • 10.
    External Tables AdvantagesThe EXTERNAL_TABLE command-line parameter: NOT USED – This is the default value. In this case, the load is done using conventional or direct path mode. GENERATE ONLY – The load job is not performed. Instead, all of the SQL statements to be executed for the whole load job are written to the specified SQL*Loader log file. The load can be done later by executing the statements in the log file EXECUTE – The load job is performed using external tables by executing SQL statements. If any of the statements fail and return an error, the attempt to load stops. Statements are always placed in the lof gile except the directory statements as they are executed. If the EXECUTE or GENERATE_ONLY option is specified, the userid that loads should be granted the following privileges: CREATE ANY DIRECTORY DROP ANY DIRECTORY
  • 11.
    External Table DisadvantagesIn an external table load for which the data file character set is UTF8 or UTF16, it is not possible to suppress checking for byte-order marks. The suppression is only necessary if the beginning of the data file contains binary data that matches the byte-order mark encloding. It is possibel to suppress byte-order mark checking with usual loads.
  • 12.
    Possible Issues Ownershipof the External Tables
  • 13.
    Where to GetMore Information Oracle9i Recovering Lost Data – Oracle Metalink – Doc 174425.1 Parameters FLASHBACK_SCN & FLASHBACK_TIME: Point in Time Export – Oracle Metalink – Doc 204334.1 Flashback Query: Confusion on SCN based – Oracle Metalink – Doc 302681.999 Oracle 9i New Features Flashback – Oracle Metalink – Doc 143217.1