Exforsys

Home arrow Reviews arrow Oracle Database Management Utilities

Oracle Utilities - A Basic External Table

Author: Packt Publishing     Published on: 4th Jan 2010

The create table command syntax is just like any other regular table creation (A), (B), up to the point where the ORGANIZATION EXTERNAL (C) keyword appears, this is the point where the actual External Table definition starts.

 

Ads

Here is the source code of the External Table creation.

In this case the External Table is accessed by the ORACLE_LOADER driver (D). Next, the external flat file is defined, and here it is declared the Oracle DIRECTORY (E) where the flat file resides. The ACCESS PARAMETERS (F) section specifies how to access the flat file and it declares whether the file is a fixed or variable size record, and which other SQL*Loader loading options are declared. The LOCATION (H) keyword defines the name of the external data file. It must be pointed out that as this is an External Table managed by the SQL_LOADER driver the ACCESS_PARAMETERS section must be defined, in the case of External Tables based on the DATAPUMP_DRIVER this section is not required.

The columns are defined only by name (G), not by type. This is permitted from the SQL*Loader perspective, and allows for dynamic column definition. This column schema definition is more flexible, but it has a drawback--data formats such as those in DATE columns must match the database date format, otherwise the row will be rejected. There are ways to define the date format working around this requirement. Assuming the date column changes from its original default format mask "DD-MON-RR" to "DD-MM-RR", then the column definition must change from a simple CHAR column to a DATE with format mask column definition.

Original format: "HIRE_DATE" CHAR(255) Changed format: "HIRE_DATE" DATE "DD-MM-RR"

When working with an External Table, the access parameter is not validated at creation time, so if there are malformed rows, or if there are improperly defined access parameters, an error is shown, similar to the one below.


Sample Code
  1.  
  2.     ERROR at line 1:
  3.     ORA-29913: error in executing ODCIEXTTABLEFETCH callout
  4.     ORA-30653: reject limit reached
  5.     ORA-06512: at "SYS.ORACLE_LOADER", line 52
  6.  
Copyright exforsys.com


Once the data is created and all required OS privileges have been properly validated, the data can be seen from inside the database, just as if it were a regular Oracle table.

This table is read only, so if the user attempts to perform any DML operation against it, it will result in this error:


Sample Code
  1.  
  2. SQL> delete ext_employees
  3. delete ext_employees
  4.        *
  5. ERROR at line 1:
  6. ORA-30657: operation not supported on external organized table
  7.  
Copyright exforsys.com


As the error message clearly states, this kind of table is only useful for read only operations.

This kind of table doesn't support most of the operations available for regular tables, such as index creation, and statistics gathering, and these types of operations will cause an ORA-30657 error too. The only access method available for External Tables is Full Table Scan, so there is no way to perform a selective data retrieval operation.

The External Tables cannot be recovered, they are just metadata definitions stored in the dictionary tables. The actual data resides in external files, and there is no way to protect them with the regular backup database routines, so it is the user's sole responsibility to provide proper backup and data management procedures. At the database level the only kind of protection the External Table receives is at the metadata level, as it is an object stored as a definition at the database dictionary level. As the data resides in the external data file, if by any means it were to be corrupted, altered, or somehow modified, there would be no way to get back the original data. If the external data file is lost, then this may go unnoticed, until the next SELECT operation takes place.

This metadata for an External Table is recorded at the {USER | ALL | DBA}_TABLES view, and as this table doesn't actually require physical database storage, all storage related columns appear as null, as well as the columns that relate to the statistical information. This table is described with the {USER | ALL | DBA}_EXTERNAL_TABLES view, where information such as the kind of driver access, the reject_limit, and the access_parameters, amongst others, are described.

Sample Code
  1.  
  2. SQL> DESC USER_EXTERNAL_TABLES
  3.   Name                                   Null?      Type
  4.  ------------------------------- -------- --------------
  5.  TABLE_NAME                             NOT NULL VARCHAR2(30)
  6.  TYPE_OWNER                                        CHAR(3)
  7.  TYPE_NAME                              NOT NULL VARCHAR2(30)
  8.  DEFAULT_DIRECTORY_OWNER                           CHAR(3)
  9.  DEFAULT_DIRECTORY_NAME                 NOT NULL VARCHAR2(30)
  10.  REJECT_LIMIT                                      VARCHAR2(40)
  11.  ACCESS_TYPE                                       VARCHAR2(7)
  12.  ACCESS_PARAMETERS                                 VARCHAR2(4000)
  13.  PROPERTY                                          VARCHAR2(10)
  14.  
Copyright exforsys.com


 

Ads

This is the first basic External Table, and as previously shown, its creation is pretty simple. It allows external data to be easily accessed from inside the database, allowing the user to see the external data just as if it was already loaded inside a regular stage table.



 
This tutorial is part of a Oracle Database Management Utilities tutorial series. Read it from the beginning and learn yourself.

Oracle Database Management Utilities

 

Comments