Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-11-07
3
Medium Priority
?
368 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

971 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