Solved

Sql Loader

Posted on 2007-12-05
4
603 Views
Last Modified: 2013-12-18
We have 10 column in the datafile and 3 column  in our staging table. We need to pick the 7th column out of the data file and append into the 2nd column of the staging table using sql loader.  This is what we have for syntax so far.

LOAD DATA
INFILE 'C:\DATA.txt'
BADFILE 'C:\DATA.bad'
DISCARDFILE 'C:\DATA.dsc'
APPEND INTO TABLE "STAGING_TABLE"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
  (COLUMN_1,  COLUMN_2,   COLUMN_3)
 
This syntax seems to insert the first 3 columns from the datafile to the 3 columns in the staging tables, it won't allow us to pick the 7th column for the datafile to insert into the 2nd column in the staging table.  This does not seem to work. Any help would be great
0
Comment
Question by:rrisal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
joebednarz earned 500 total points
ID: 20415271
I would avoid using Sql Loader.  Try, instead, using externally organized tables:

SQL> create table MY_EXTERNAL_TABLE
  2      ( empl_id varchar2(3),
  3        last_name varchar2(50),
  4        first_name varchar2(50),
  5        ssn varchar2(9),
  6       email_addr varchar2(100),
  7        years_of_service number(2,0)
  8      )
  9      organization external
 10      ( default directory ORACLE_DIRECTORY_OBJECT
 11        access parameters
 12        ( records delimited by newline
 13          fields terminated by ','
 14        )
 15        location ('my_data_file.csv')  
 16    );

From there, you simply can do an INSERT accessing the "external" data in an SQL query.
0
 
LVL 9

Expert Comment

by:joebednarz
ID: 20415290
In case you need it:

CREATE OR REPLACE DIRECTORY oracle_directory_object
AS 'C:\my_directory';

GRANT READ ON DIRECTORY oracle_directory_object TO user_name;

Then make sure your data file is in the directory specified...
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

730 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