<

Attach Dbase IV Data Files To Oracle Database

Published on
4,641 Points
1,341 Views
3 Endorsements
Last Modified:
Overview

This past end of year brought us new requirements to download “compliance” files from government entities and the additional burden of maintaining these file updated monthly.

Some of these files are ‘Dbase IV’ (.dbf file format) which made it a manual procedure to load and maintain the data in Oracle tables.

To deal with this situation and be able to automate this process we coded a PL/SQL procedure to transform these “.dbf” files to pipe-delimited files and use as part of the ETL script.

This “ATTACH_DBF_FILE” procedure  provides the means to convert a ‘Dbase IV’ database file to a pipe-delimited file and attach the converted file to an oracle database as an external table.

Perhaps there already exists a Unix utility that does this, but with budget and time constraints we had to code our own.

How it Operates
 

1.

Open the dbf file as BLOB.

2.

Analyze and extract metadata for the structure and fields from the dbf file header:

a.      Field name
b.      Type
c.      Length
d.      Decimals
e.      Auto-Increment

3.

Build and execute DDL to create the external table.

4.

Extract the data from the dbf file and write to pipe delimited file.
Parameters

PROCEDURE Attach_Dbf_File
(
  P_Directory         VARCHAR2
, P_File_Name        VARCHAR2
, P_Schema            VARCHAR2
, P_Delimiter         VARCHAR2    DEFAULT '|'
)

Parameter   Description

Directory             Directory object pointing to the location of the dbf
                             and the pipe delimited file on the server.

File name            Name of the dbf file
Schema               Target schema name
Delimiter             Default is pipe “|”

Code is here

attach-dbf-file.sql

NO WARRANTY

THE PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW THE AUTHOR WILL BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
3
Comment
Author:MikeOM_DBA
1 Comment
 
LVL 39

Expert Comment

by:Geert G
nice article ... i could have used this 2 decades ago !
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month