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 > Updating Temporary tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-06, 11:08
PRBR PRBR is offline
Registered User
 
Join Date: Mar 2006
Posts: 6
Updating Temporary tables

Hi

I am trying to update a column from a temporary table in db2 v8. I am getting -151 error.

I have defined the temporary table as
DECLARE GLOBAL TEMPORARY TABLE SESSION.abcd(col1,col2,col3)

my update stmt is
update session.abcd set col2 = (select ah.col2 from xyz ah
where ah.col1 = 10)

Is it possible to update like above.

Thanks
Reply With Quote
  #2 (permalink)  
Old 03-03-06, 11:40
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Yes. I think your problem is how you created your temp table.
Try something like this:

DECLARE GLOBAL TEMPORARY TABLE abcd(col1 int,col2 int,col3 int) on commit preserve rows not logged;

HTH

Andy
Reply With Quote
  #3 (permalink)  
Old 03-03-06, 13:32
PRBR PRBR is offline
Registered User
 
Join Date: Mar 2006
Posts: 6
Hi,

I have tried putting DEFINITION ONLY WITH REPLACE ON COMMIT PRESERVE ROWS NOT LOGGED;

I got compilation error saying that --
";" REQUIRED
INVALID KEYWORD "WITH";

Can you help me identify the problem.

Thanks
Reply With Quote
  #4 (permalink)  
Old 03-03-06, 13:34
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Can you please post you entire DECLARE statement. Also you DB2 version and OS.

Andy
Reply With Quote
  #5 (permalink)  
Old 03-03-06, 14:12
PRBR PRBR is offline
Registered User
 
Join Date: Mar 2006
Posts: 6
declare stmt

It is DB2 V8 on Zos

DECLARE GLOBAL TEMPORARY TABLE SESSION.ACCESS_ROWS AS (
SELECT AH.ACCESS_TIMESTAMP AS ACCESS_TIME,
AH.CUSTOMER_NO AS CUST_NO
FROM HISTORY AH)
DEFINITION ONLY ON COMMIT PRESERVE ROWS;


I have tried the above statement - it compiled and we got --151 on the update statement.

Update statement is as follows:

update access_rows set cust_no = (select customer_no from history ah where ah.abcd = 10)

Thanks
Reply With Quote
  #6 (permalink)  
Old 03-03-06, 14:19
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What do you do to the temp table between when you declare it and you try to update?

Andy
Reply With Quote
  #7 (permalink)  
Old 03-03-06, 15:04
PRBR PRBR is offline
Registered User
 
Join Date: Mar 2006
Posts: 6
insert into temp table

Between declaring the temp table and updating it, I am inserting into the temp table as follow

insert into session.access_rows select abcd, xyz from customer where xyz = 10;

Then we are updating the temp table using the update statement.

Thanks.
Reply With Quote
  #8 (permalink)  
Old 03-03-06, 15:17
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What happens if you declare the table like this:

DECLARE GLOBAL TEMPORARY TABLE SESSION.ACCESS_ROWS (ACCESS_TIME timestamp, CUST_NO int)
ON COMMIT PRESERVE ROWS not logged with replace;

Andy
Reply With Quote
  #9 (permalink)  
Old 03-03-06, 15:31
PRBR PRBR is offline
Registered User
 
Join Date: Mar 2006
Posts: 6
-151 on update stmt

We are getting -151 on the update stmt.
Reply With Quote
  #10 (permalink)  
Old 03-03-06, 15:39
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Please post the full error.

Andy
Reply With Quote
  #11 (permalink)  
Old 03-03-06, 15:55
PRBR PRBR is offline
Registered User
 
Join Date: Mar 2006
Posts: 6
sqlcode going into an error table

Hi,

We are inserting the sqlcode into an error table. We are checking the error table after executing the stored procedure.

In the sqlcode field -151 is there with comments in another field. This is how, I am saying that the update stmt is failing.

Compilation and bind process are going through successfully.

Execution of the stored procedure is returning the result cursor in the update statement error log area.

Thanks
Reply With Quote
  #12 (permalink)  
Old 03-03-06, 16:07
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I am not at all familiar with ZOS, so my help may not be of any use. What happens when you try the commands in the CLP?

Andy
Reply With Quote
  #13 (permalink)  
Old 03-03-06, 18:40
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
FYI, There is no 'WITH REPLACE' on zOS

Cheers
sathyaram

Quote:
Originally Posted by PRBR
Hi,

I have tried putting DEFINITION ONLY WITH REPLACE ON COMMIT PRESERVE ROWS NOT LOGGED;

I got compilation error saying that --
";" REQUIRED
INVALID KEYWORD "WITH";

Can you help me identify the problem.

Thanks
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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