Data Warehousing Community Forum

Databases => Oracle => Topic started by: Sipra on July 03, 2008, 11:34:03 am



Title: Processing a .CSV file to Table
Post by: Sipra on July 03, 2008, 11:34:03 am
HI Friends,

Please le tme know how to process a .CSV file to Table by using SQL loader Concept.

No other technique required...! Know it can be done thru various processes. But need to acquire this in the above way...
 ;D


Title: Re: Processing a .CSV file to Table
Post by: unknown on July 04, 2008, 03:20:00 pm
SQL Loader is a bulk loader utility used for moving data from external files (.CSV, .txt, .dat, excel, .xml, etc.,)  into the Oracle database. SQL Loader supports various load formats, selective loading, and multi-table loads.

Look at the following example -

Have to be executed at the command prompt  -
            sqlldr username@server/password control=loader.ctl

Before executing this, you have to prepare a control file which is mentioned in the above command line (eg - loader.ctl)
This sample control file (loader.ctl) will load an external data file containing delimited data -
loader.ctl contents -
 
        load data
        infile 'c:\data\mydata.csv'
        into table emp
        fields terminated by "," optionally enclosed by "'"       
        (empno,
        empname,
        sal,
        deptno
        hiredate date "ddmonyyyy"
        )

This will automatically creates a log file and a bad file which will have the log details and rejected data respectively.

The above one is an example of simple SQL loader for delimited .csv file.


Title: Re: Processing a .CSV file to Table
Post by: Sipra on July 15, 2008, 06:00:19 pm

        fields terminated by "," optionally enclosed by "'"       
Finally, it worked with some other options -

        fields terminated by "," optionally enclosed by ""/"   
        fields terminated by "," optionally enclosed by "\"" trailing nullcols    
       
as all the varchar/date fields in the .csv files are quoted with double quotes.
And also by increasing the error count to some maximun satisfied value.


Title: Re: Processing a .CSV file to Table
Post by: ecearundeva on March 24, 2009, 02:22:17 pm
Hi,

To check which options are available in any release of SQL*Loader use this command:
sqlldr help=y

From the above post(Posted by: unknown)
He/She mentioned that   
Control file to load data:

Quote
load data
        infile 'c:\data\mydata.csv'
        into table emp
        fields terminated by "," optionally enclosed by "'"       
        (empno,
        empname,
        sal,
        deptno
        hiredate date "ddmonyyyy"
        )


This will automatically creates a log file and a bad file which will have the log details and rejected data respectively.

Yes by typing this " sqlldr username@server/password control=loader.ctl" on the command prompt, log file file will get generated.
But to get bad file , you need to include
BADFILE 'c:\temp\filename.bad' in the control file.

You can learn much more from here
Quote
reference#1 (http://www.psoug.org/reference/OLD/sqlloader.html?PHPSESSID=f143fd358ef8e0e9c97c3b1ff081b511)
reference#2 (http://www.verio.com/support/documents/view_article.cfm?doc_id=1513)

Admin - retouched as per the rules