Solved

Sql Loader Scripts in Oracle

Posted on 2011-03-10
12
674 Views
Last Modified: 2012-05-11
Hi,
 Below is one of the  sql loader script which is being used to  load data into oracle tables. But while the data is being loaded it creating spaces in the rows. How to avoid this space

LOAD DATA
INFILE    '/usr/summary/DBload.txt'
BADFILE   '/usr/Scripts/error_book.bad'
DISCARDFILE '/usr/Scripts/error_book.dsc'
APPEND
INTO TABLE INFO_STAGE
FIELDS TERMINATED BY "|"
TRAILING NULLCOLS
(
    ID,
    TITLE,
    TOTA_FILES,
    STATUS char "nvl(:STATUS,'N')"

)
0
Comment
Question by:new_perl_user
[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
  • 6
  • 6
12 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 35098617
try:

LOAD DATA
INFILE    '/usr/summary/DBload.txt'
BADFILE   '/usr/Scripts/error_book.bad'
DISCARDFILE '/usr/Scripts/error_book.dsc'
APPEND
INTO TABLE INFO_STAGE
FIELDS TERMINATED BY "|"
TRAILING NULLCOLS
(
    ID "trim(:id),
    TITLE "trim(:title)",
    TOTA_FILES,
    STATUS char "nvl(:STATUS,'N')"

)
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35098623
I guess I should ask:  The columns in the table are varchar2 and not char correct?
0
 

Author Comment

by:new_perl_user
ID: 35098640
yes the columns are varchar
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35098721
See if the trims work for you.  TOTA_FILES sounded like a number so I didn't add it there.
0
 

Author Comment

by:new_perl_user
ID: 35098926
I tried Trim but it did not work. I mean still it is generating some space while loading.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35098938
Can you post the table definition and some sample data from '/usr/summary/DBload.txt'?

I'll see if I can recreate this on my database.
0
 

Author Comment

by:new_perl_user
ID: 35099070
Table:
ID               VARCHAR2(25 byte)
TITLE          VARCHARE2(256 byte)
TOTAL_FILES   NUMBER
STATUS            CHAR

Attached is the sample file I am trying to load.  
DBload.txt
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35099153
It seems fine to me.  My test was done with Oracle 10.2.0.3 on Windows.

drop table tab1 purge;
create table tab1(
ID            VARCHAR2(25 byte),
TITLE         VARCHAR2(256 byte),
TOTAL_FILES   NUMBER,
STATUS        CHAR(1)
);


-- load the data with:  sqlldr user/password control=q.ctl

--check for spaces
select
':' || ID           || ':',
':' || TITLE        || ':',
':' || TOTAL_FILES  || ':',
':' || STATUS       || ':'
from tab1;



:5542335P:
:An enquiry into the nature, cause and cure, of the angina suffocativa,/:
:44:                                       :N:


1 row selected.

LOAD DATA
INFILE    *
APPEND
INTO TABLE tab1
FIELDS TERMINATED BY "|"
TRAILING NULLCOLS
(
    ID,
    TITLE,
    TOTAL_FILES,
    STATUS char "nvl(:STATUS,'N')"

)
begindata
5542335P|An enquiry into the nature, cause and cure, of the angina suffocativa,/|44|

Open in new window

0
 

Author Comment

by:new_perl_user
ID: 35099550
It is working now with  the trim option, Thank You.  One more thing  I have another loader Script which is creating am empty row after the load is done. How to  overcome that empty row.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35099575
>>One more thing  I have another loader Script which is creating am empty row after the load is done. How to  overcome that empty row.

Is there a blank line in the data file that might be getting loaded?

You should probably open a new question and provide the details or that control file.  Be sure to provide sample data that reproduces the problem you describe.

If we can reproduce what you describe, it's a lot easier to provide a solution.

0
 

Author Comment

by:new_perl_user
ID: 35099607
Sure. I will close this and open a new one and post the details.
0
 

Author Comment

by:new_perl_user
ID: 35099757
Hi,
A new question was opened for the above problem with title "sql loader empty row". If possible can you look into it. I am closing this.

Thanks,
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

632 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