If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Stored procedures and file system

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-02-04, 16:52
saltbits saltbits is offline
Registered User
 
Join Date: Jun 2004
Posts: 28
Stored procedures and file system

I've read that Stored Functions have access to the file system - like reading flat files etc. may be possible.

But is the same possible from within Stored Procedures? I am trying to create a SP with a LOAD statement and it seems like its not right.

Could someone help?
Thanks.
Reply With Quote
  #2 (permalink)  
Old 07-05-04, 09:30
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by saltbits
I've read that Stored Functions have access to the file system - like reading flat files etc. may be possible.

But is the same possible from within Stored Procedures? I am trying to create a SP with a LOAD statement and it seems like its not right.

Could someone help?
Thanks.
What type of Stored Procedure? (ie. SQL? C?)
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 07-06-04, 13:38
saltbits saltbits is offline
Registered User
 
Join Date: Jun 2004
Posts: 28
Just plain SQL SP. And by the way, going by your reply to my question on another thread - the SP is using LOAD to database table, not temporary table (was just trying an alternative...)

Thanks.
Reply With Quote
  #4 (permalink)  
Old 07-06-04, 14:32
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by saltbits
Just plain SQL SP. And by the way, going by your reply to my question on another thread - the SP is using LOAD to database table, not temporary table (was just trying an alternative...)

Thanks.
Unfortunately I don't think LOAD is supported from an SQL Stored Proc... maybe someone will correct me.

What's the problem you're trying to solve? Maybe there's another way to kick that cat.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #5 (permalink)  
Old 07-06-04, 14:42
saltbits saltbits is offline
Registered User
 
Join Date: Jun 2004
Posts: 28
>What's the problem you're trying to solve? Maybe there's another way to kick that cat.

OK, here is what I need to do:
I have to read a txt file that has one column worth of data. I update a certain table in the db where PK = the value read from the flat file - like this:
UPDATE Table1 SET stat='FAILURE' WHERE EXISTS (SELECT * FROM Temp1 WHERE Table1.PK = Temp1.key);

I was hoping that Temp1 would be a global temp table which I now know I cant use. So basically, its a question of an alternative way to read the flat file and use it in the update statement.

(I am doing all this in UNIX, so if there is a UNIX way to do it all, that would help too!)

Thanks a lot.
Reply With Quote
  #6 (permalink)  
Old 07-06-04, 14:54
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by saltbits
>What's the problem you're trying to solve? Maybe there's another way to kick that cat.

OK, here is what I need to do:
I have to read a txt file that has one column worth of data. I update a certain table in the db where PK = the value read from the flat file - like this:
UPDATE Table1 SET stat='FAILURE' WHERE EXISTS (SELECT * FROM Temp1 WHERE Table1.PK = Temp1.key);

I was hoping that Temp1 would be a global temp table which I now know I cant use. So basically, its a question of an alternative way to read the flat file and use it in the update statement.

(I am doing all this in UNIX, so if there is a UNIX way to do it all, that would help too!)

Thanks a lot.
What about a shell script? ie. if your db name is SAMPLE and your file is lines.txt:

#!/bin/ksh

db2 CONNECT TO SAMPLE
for val in `cat lines.txt`
do
db2 UPDATE Table1 SET stat=\'FAILURE\' WHERE Table1.PK = \'$val\'
done
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #7 (permalink)  
Old 07-06-04, 14:54
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Something like this?
Code:
awk '{"db2 update table1 set stat='\''"FAILURE"'\''" where pk=" $1}' your_txt_file | sh
May be a bit slow to run but quick to implement :-)
Reply With Quote
  #8 (permalink)  
Old 07-06-04, 15:05
saltbits saltbits is offline
Registered User
 
Join Date: Jun 2004
Posts: 28
Great! I think I will just try these UNIX ways.

Thanks a lot, everyone.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On