Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 18th, 2005, 04:25 PM
Michael Bader
Guest
 
Posts: n/a
Default Pushing content of a file into a varchar field?

Hi,

maybe a stupid question, but I can't find an answer to it:
we have a web-based application system, where the texts of
the reply mails are held in a DB2 database (in varchar fields).
To input the texts via the db2 prompt is a pain, because of
the numerous escape characters.
I was thinking about importing the varchar content from a file,
but I don't find how to do it. I'm thinking about something
like 'update ... set field=[content of file] where ...'
Is there an easy solution for this?

Thanks in advance

Michael




  #2  
Old November 19th, 2005, 09:45 AM
Thiru
Guest
 
Posts: n/a
Default Re: Pushing content of a file into a varchar field?

Hi,
Use Import Command.. That is so simple..

Regards,
Thiru.
WantedToBeDBA.
Certified DB2 DBA.

  #3  
Old November 21st, 2005, 09:05 AM
Michael Bader
Guest
 
Posts: n/a
Default Re: Pushing content of a file into a varchar field?

Thiru wrote:
[color=blue]
> Hi,
> Use Import Command..[/color]

I did. However, it seems to be impossible to change a single field.
I can of course import an entire set of vaues into a table, but
that's not necessarily what I want to do. Moreover, the import didn't
work to well with .del-files. And I'm reluctant to modify the
..ixf-files ...
I was hoping for a shorter solution. Isn't there any?

Michael

  #4  
Old November 21st, 2005, 09:05 AM
Knut Stolze
Guest
 
Posts: n/a
Default Re: Pushing content of a file into a varchar field?

Michael Bader wrote:
[color=blue]
> Hi,
>
> maybe a stupid question, but I can't find an answer to it:
> we have a web-based application system, where the texts of
> the reply mails are held in a DB2 database (in varchar fields).
> To input the texts via the db2 prompt is a pain, because of
> the numerous escape characters.
> I was thinking about importing the varchar content from a file,
> but I don't find how to do it. I'm thinking about something
> like 'update ... set field=[content of file] where ...'
> Is there an easy solution for this?[/color]

You can use a UDF that opens the file (passed as parameter to the UDF) and
returns the file's content as VARCHAR. Then a simple INSERT or UPDATE will
do the trick:

INSERT INTO tab
VALUES ( ..., readMailFromFile(<file-name>), ... )


Using IMPORT would be more complicated as you'd have to build a proper CSV
file or so, and that might be a pain as you have to take care of escaping
again.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
  #5  
Old November 23rd, 2005, 10:55 PM
Stefan Momma
Guest
 
Posts: n/a
Default Re: Pushing content of a file into a varchar field?

Knut Stolze wrote:[color=blue]
> Michael Bader wrote:
>[color=green]
>> Hi,
>>
>> maybe a stupid question, but I can't find an answer to it:
>> we have a web-based application system, where the texts of
>> the reply mails are held in a DB2 database (in varchar fields).
>> To input the texts via the db2 prompt is a pain, because of
>> the numerous escape characters.
>> I was thinking about importing the varchar content from a file,
>> but I don't find how to do it. I'm thinking about something
>> like 'update ... set field=[content of file] where ...'
>> Is there an easy solution for this?[/color]
>
> You can use a UDF that opens the file (passed as parameter to the UDF) and
> returns the file's content as VARCHAR. Then a simple INSERT or UPDATE will
> do the trick:
>
> INSERT INTO tab
> VALUES ( ..., readMailFromFile(<file-name>), ... )
>
>
> Using IMPORT would be more complicated as you'd have to build a proper CSV
> file or so, and that might be a pain as you have to take care of escaping
> again.
>[/color]

This works fine for me for a very trivial table:

db2 create table mail(id int not null primary key, text varchar(3000))
db2 load from loadit of del lobs from `pwd` modified by coldel, insert
into mail

where 'loadit' is a CSV file in the current directory containing id and
filename, separated by comma:

1,mail01
2,mail02
3,mail03
..
..
..

Cheers,

-- stefan
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles