Solved

Sql Loader Scripts in Oracle

Posted on 2011-03-10
12
670 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
  • 6
  • 6
12 Comments
 
LVL 76

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 76

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
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 76

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 76

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 76

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 76

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
report returning null 21 92
Get the parent node - XMLTYPE 9 69
oracle 11g 23 73
pl/sql - query very slow 26 57
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

813 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