Solved

How to load a pipe delimited text file to a database table in DB2

Posted on 2010-11-12
10
3,884 Views
Last Modified: 2012-05-10
Hi,

I want to load a text file to a database table in DB2. If it is a comma delimited file, it is loading perfectly, but if it is pipe delimited, it is failing. Why is that? I want to be able to keep the option of using both pipe or comma delimited files. here is the command I am using for comma delimited which is working fine--

module load ibmdb2/client/8.2.7
db3 connect to DataBase_Server
db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL,INSERT INTO myinfo check pending cascade immediate

But if I use pipe, it is failing.

module load ibmdb2/client/8.2.7
db3 connect to DataBase_Server
db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL|INSERT INTO myinfo check pending cascade immediate

Can I have the option of specifying the syntax in such a way, that it is either a pipe or a comma delimited file?
0
Comment
Question by:sunny82
  • 5
  • 3
  • 2
10 Comments
 
LVL 45

Expert Comment

by:Kdo
ID: 34121286
Hi Sunny,

DB2 has no issue with your using a pipe symbol as the field delimiter.  My guess is that the underlying operating system is attempting to handle the pipe symbol so that DB2 never sees it.

If you'll escape the symbol, you should be fine.

What's the underlying operating system?



Kent
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 34121296
the answer is no
you can't have mixed delimiters in your file
it is either comma or pipe (or any other character...) but it has to be consistent
0
 
LVL 45

Expert Comment

by:Kdo
ID: 34121323
You can also quote the delimiter character, depending on the O/S.

  LOAD .. MODIFIED BY COLDEL'|'

or

  LOAD .. MODIFIED BY COLDEL "|"


Kent
0
 

Author Comment

by:sunny82
ID: 34121457
If I use LOAD .. MODIFIED BY COLDEL'|'

I am getting the following
SQL0104N  An unexpected token "END-OF-STATEMENT" was found following
"IMMEDIATE".  Expected tokens may include:  "REMOTE".  SQLSTATE=42601

If I use  LOAD .. MODIFIED BY COLDEL "|"
same error as above

If I use LOAD .. MODIFIED BY COLDEL \|
same error as above

If I use LOAD .. MODIFIED BY COLDEL|
-ksh: INSERT: not found [No such file or directory]

On the other hand,
LOAD .. MODIFIED BY COLDEL,
is working perfectly

The underlying OS is Unix

0
 

Author Comment

by:sunny82
ID: 34121550
Any ideas why this peculiar behavior is happening and how to solve it.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 45

Expert Comment

by:Kdo
ID: 34121554
If I use  LOAD .. MODIFIED BY COLDEL "|"
same error as above


Take out the space between COLDEL and "|"



0
 

Author Comment

by:sunny82
ID: 34121724
This is what I ran, there is no space between COLDEL and "|"

db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL"|"INSERT INTO myinfo check pending cascade immediate

giving me the error

SQL0104N  An unexpected token "END-OF-STATEMENT" was found following
"IMMEDIATE".  Expected tokens may include:  "REMOTE".  SQLSTATE=42601
0
 

Author Comment

by:sunny82
ID: 34121811
On the other hand, if I do this --

db2 load client from '~/file/myinfo.txt' of del MODIFIED BY COLDEL,INSERT INTO myinfo check pending cascade immediate

It works just fine

0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 34121818
the easiest solution will probably be to write the hex representation of |

from information center:
The character must be specified in the code page of the source data.
The character code point (instead of the character symbol), can be specified using the syntax xJJ or 0xJJ, where JJ is the hexadecimal representation of the code point. For example, to specify the # character as a column delimiter, use one of the following:
    ... modified by coldel# ...
   ... modified by coldel0x23 ...
   ... modified by coldelX23 ...

0
 

Author Comment

by:sunny82
ID: 34124289
The Hex solution worked finally !!! Many thanks..

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

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

16 Experts available now in Live!

Get 1:1 Help Now