Solved

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

Posted on 2013-11-07
3
355 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

947 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

21 Experts available now in Live!

Get 1:1 Help Now