?
Solved

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

Posted on 2010-11-12
10
Medium Priority
?
4,811 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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