Solved

URGENT How to export with PL/SQL, data from Oracle tables into DBF files

Posted on 2006-06-16
18
3,551 Views
Last Modified: 2007-12-19
I have the following problem:
I want to export, through PL/SQL, data from a Oracle table directly to a DBF file.

I think that is beeing done with UTL_FILE function, but i don't know how to write the DBF file header.

I want that export to happen at the user request from a form.
The file then will be e-mailed or put on a CD.

Another question: UTL_FILE put the file on the server (i'm using Oracle Database 9.2 and 9iAS 9.2). How to transfer automatically the file to the user's HDD?

2 questions, both hard, i think.

Please help if u have any informations, links, etc.
0
Comment
Question by:mitralier
  • 6
  • 6
  • 3
  • +2
18 Comments
 
LVL 16

Accepted Solution

by:
MohanKNair earned 250 total points
Comment Utility
It is possible to read a dbase file using UTL_FILE and PL/SQL package. The package is available in the link below. The package can be modified to write in dbase format.
http://asktom.oracle.com/pls/ask/f?p=4950:8:3567412298036405208::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:711825134415

Xbase File Format Description is available in this link
http://www.clicketyclick.dk/databases/xbase/format/
0
 
LVL 25

Expert Comment

by:jrb1
Comment Utility
What kind of server do you have?  Unix or Windows?  Either way, the answer isn't simple.  How does the user access the database?  We have a web-based system that we access data through, and that system is responsible for FTPing files directly to users.  The database can't do that.

In your case, you can trigger an FTP from Oracle:

http://www.oracle-base.com/articles/9i/FTPFromPLSQL9i.php
0
 
LVL 47

Assisted Solution

by:schwertner
schwertner earned 250 total points
Comment Utility
The normal way to transfer data between different types of DBs are the flat files.
In Oracle you can do this either using UTL_FILE package
or SPOOL and SELECT:
SQL>spool c:\some_file.txt
SQL>set heading 0
SQL> select name || ','||address from spme table;
SQL>spool off
0
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
Second question; invoking ftp.
0
 
LVL 1

Author Comment

by:mitralier
Comment Utility
OK.
I've done, so far, the following
Using WebUtil for Oracle Forms i'v done a csv file directly from the database, that is saved directly on the client computer.

That's a problem solved for the tranfer of the file.

The remaining problem is how to write the DBF file, because it's a binary file and the header must be extremely exact.
If someone could help at this.............

At the end i will split the points, don't know exactly how :)

P.S. The FTP was not an option from the start, because of the security of the network. WebUtil it's the best for this, i think.
0
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
Now using Excel create csv file (that is really character, not binary file) and try to read and insert the records into XBase system.
0
 
LVL 1

Author Comment

by:mitralier
Comment Utility
That's my problem schwertner, i don't know how to write in a dBASE system file.
I need a procedure that write the header and another procedure that write the actual data. I don't know what to use in any of them. The problem is that i will have to use WebUtil to build those procedures, because the file is written in Oracle Forms, not on a stored procedure.
0
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
It is a bad idea to try 'to write in a dBASE system file'!
Every system has tools to read flat files and to put the records into the dbf files.
I personally did in 1997 the reverse task: In Clipper 5 I created flat file with Oracle "Insert" statements.
May be Dbase has its insert statement. If so it is easy to format the Oracle output to fit
the Dbase input.

Another option:
http://www.sharewareplaza.com/Data-Loader-download_26345.html

Description:
Data Loader is a simple yet powerful tool to import and export Data between many common formats. Current Data Loader Ver. 1.0 supports Oracle, MS Access, FoxPro, DBF's and Delimited or Flat Files. You can use Data Loader to transfer data from one database format to another database format. While transferring you can filter columns and specify WHERE conditions.
It supports Long , Picture Data types. In a jiffy you can copy data without any coding.
Supported O/s: Win 2003, Win 2000, XP, Win ME,Win98 &Win95
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:mitralier
Comment Utility
Ok, i think it's a misundersting here.

The actual problem is:

I have a form that call a stored procedure.
The stored procedure return the array with the data of the file.
The form writes the array into a .CSV file. For writing the file i use "client_text_io.putf" from WebUtil. That command create and write into a file on the client computer.

Now, i want that .CSV file to be a .DBF file, and after the export from my form to import it in FoxPro.
I don't know how to write the header of the DBF file and how to write the actual data. In CSV the data are comma delimited. In DBF.......HOW?


0
 
LVL 1

Author Comment

by:mitralier
Comment Utility
Oh, and i can't use a tool, the EXPORT it's gonna be integrated into an application, it's not for a one time use.
The user  will pick a table and then export it. I have that functionality, but the file is CSV. I want the file to be .DBF now.
0
 
LVL 16

Expert Comment

by:MohanKNair
Comment Utility
Instead of CSV file create a tab delimited file. This is accessible by Microsoft tools like excel.  
The comma character CSV file can be converted to TAB character by using another PL/SQL code.
0
 
LVL 1

Author Comment

by:mitralier
Comment Utility
I need a binary file, not a character file. Not tab delimited, comma delimited or any kind of delimited.
And i don't want to open it with Excel.
I want to open that file directly with FoxPro, after the export.
0
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
There are such convertor programs, but most of them are paid.
Search using Google ...
0
 
LVL 1

Author Comment

by:mitralier
Comment Utility
Schwertner, i want to build such a program in PL/SQL and Forms, not using one.
0
 
LVL 47

Expert Comment

by:schwertner
Comment Utility
I see and understand. This is what I found:


How to Create a DBase File from Reports

Report Builder supports the following destination formats (DESFORMAT):
PDF, HTML, HTMLCSS, HTMLCSSIE, RTF, XML, DELIMITED. So there is no direct way
to create dBase file from Reports.

It is however possible to create DELIMITED report output and then
import/convert this to dBase. MS Excel can for example open delimited file and
then save the data as a *.DBF (dBase) file. This process (conversion from
delimited to *.dbf using MS Excel) can be automated using an OLE2 package.

Another method is to use the EXEC_SQL package to connect to ODBC data sources
(including dBase file) via the Open Client Adapter (OCA), which is supplied
with Developer. One can then programmatically manipulate that data source using
regular SQL statements (insert, update, delete, select). But Reports cannot
write it's output to such a datasource directly.



How to Obtain a Merant/Data Direct dBASE Driver for OFSA Import/Export


Importing and Exporting IDs

You can use import/export functionality of OFSA to:

  Transport IDs from one FDM database to another
  Maintain external backup copies of key IDs
  Load data into FDM from an external database (.DBF) source

OFSA provides two methods of importing and exporting IDs:
  Individual ID import/export
  Dependent ID import/export

Individual ID Import/Export

IDs that do not contain other embedded IDs, such as Leaf Characteristics ID and
Transfer Pricing ID, are imported and exported using the Individual ID method.
These IDs are exported into a dBase file with the.DBF extension and can be
imported only from a dBase file with the .DBF extension.


For OFSA 4.5.3 and Higher Versions:
===================================
Visit the following web site to purchase or download a trial version of the 32-
bit Data Direct dBase driver:

http://www.datadirect-technologies.com/

Go to:
-- "Download database drivers" (left side under Fast Access)
-- "DataDirect Connect for ODBC Windows"
-- Fill out form, selecting the following:
   --> Client workstation
   --> Under "Flat" files --> "dBASE"

After agreeing to the license agreement and hitting submit follow the download
instructions for "DataDirect Connect for ODBC 4.2 Windows Download".

Download the zip file for "Connect for ODBC Software for Windows, Windows
NT/2000/XP/Me/98 - Standard Pack" and double-click on the setup.exe to run
the install Wizard.  Choose to install a Desktop Single Driver.  Select the
dBASE driver.

For instructions on configuring the driver, please see  the following:
How to Setup 32-bit Merant/Data Direct dBASE Driver for Import and Export Functionality

For OFSA 4.5.2x and Lower Versions:
===================================
Use the 16-bit Merant/Data Direct Dbase Driver version 2.5.3 FA-dbase IV to
import and export OFSA IDs.

The 16-bit Merant/Data Direct Dbase Driver is no longer available for purchase.

If you already own the 16-bit Dbase driver, contact Data Direct to renew or add
more licenses.

To obtain a copy of the 16-bit Dbase driver software, a third-party vendor must
be located.  Look for vendors selling programmers and developers software and
tools and inquire about the 16-bit Merant dbase IV driver for Windows 3.x.

Note: The Merant driver was formerly known as the Intersolv driver.  It is now
called the Data Direct driver.

0
 
LVL 16

Expert Comment

by:MohanKNair
Comment Utility
See the link below. procedure dump_table in the package can be used to dump a file to disk in DBASE file format.

http://asktom.oracle.com/pls/ask/f?p=4950:8:15796147866611609094::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6379798216275#8651991032899



0
 
LVL 1

Expert Comment

by:Computer101
Comment Utility
Forced accept.

Computer101
EE Admin
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now