[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2010-11-12
10
Medium Priority
?
5,037 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
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 46

Expert Comment

by:Kent Olsen
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
LVL 46

Expert Comment

by:Kent Olsen
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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

650 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