Solved

how do i fix format of export using bcp in sql server

Posted on 2013-11-07
3
353 Views
Last Modified: 2013-11-25
When I issue the following export command

bcp " select fname, lname, dept, REPLACE(REPLACE(contract_no, CHAR(13), ''), CHAR(10), ''), audit_data from DEV.dbo.contracts" queryout "C:\exports\coontracts.txt"  -c -t"|" -r"\IAC-EOR" -T -S 127.0.0.1

the data successfully exports 1810 records

when I try to import the data into oracle using an external table

I execute the following script:

CREATE TABLE contracts_load (fname CHAR(15), lname CHAR(20), dept CHAR(20), contract_no CHAR(20), audit_data CHAR(2000))
ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY contracts_dir ACCESS PARAMETERS (RECORDS DELIMITED BY "IAC-EOR" FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY '"' LRTRIM
(fname CHAR(15), lname CHAR(20), dept CHAR(20), contract_no CHAR(20), audit_dataCHAR(2000))
LOCATION ('contracts.txt'));

the table creates successfully. However, when I do a select count(*) from contracts_load only 139 records are there. I check the log file and see the following error:

KUP-04021 field formatting error for field audit_data
KUP-04023 field start is after end of record

When I check the contracts.txt file it appears the records continue to a point and cut off. for example

lark|andrea|finance|F33760C-5006|0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*429*429**429*429**429*429**429*429**429*429**429*429**429*429**429*429**429*429**429*429**429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*IAC-EORnelson|roy|A22476-C-5007|0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*IAC-EORdawkins|jenny|D226703-K-3772|0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*521*521**521*521**521*521**521*521**521*521**521*521**521*521**521*521*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*429*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*
0*0*0*0*0*0*IAC-EOR

I added the IAC-EOR record delimiter because i was only getting 1615 records when my record delimiter was NEWLINE. There are 1810 records. Can someone help me figure out how to fix this? I am not sure if it can be done during the bcp export or fixed during the external table creation in Oracle.
0
Comment
Question by:sikyala
  • 2
3 Comments
 
LVL 9

Expert Comment

by:guswebb
ID: 39631217
You can only stream a certain amount of text using BCP so it looks like you are hitting that ceiling and your export truncates.
0
 

Accepted Solution

by:
sikyala earned 0 total points
ID: 39631507
I added the following lines to my access parameters list in the external table creation script:

MISSING FIELD VALUES ARE NULL
    REJECT ROWS WITH ALL NULL FIELDS

and successfully loaded 1810 records
0
 

Author Closing Comment

by:sikyala
ID: 39674124
yay me
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

757 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

22 Experts available now in Live!

Get 1:1 Help Now