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 > Temporary Tables in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-10, 14:36
smartcooldevil smartcooldevil is offline
Registered User
 
Join Date: Jun 2010
Posts: 17
Temporary Tables in DB2

Hi,
Can anyone please suggest me how to wite and use temporary table in DB2.

I have written follwoing query:


DECLARE GLOBAL TEMPORARY TABLE session.fred
(dept SMALLINT NOT NULL
,avg_salary DEC(7,2) NOT NULL
,num_emps SMALLINT NOT NULL);

select * from session.fred;

insert into session.fred values (1,1200,45);
insert into session.fred values (2,4560,56);
insert into session.fred values (1,8500,96);
insert into session.fred values (3,2699,36);
insert into session.fred values (2,4566,25);
select count(*) from session.fred;

select * from session.fred;
drop table session.fred;

It is not shwoing me the data in final output

Even it is shwin 0 as count(*) query.
Reply With Quote
  #2 (permalink)  
Old 07-19-10, 14:47
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
how are you running all of this? command line? program? spufi? script?
Dave
Reply With Quote
  #3 (permalink)  
Old 07-19-10, 15:16
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Turn off autocommit.
Reply With Quote
  #4 (permalink)  
Old 07-19-10, 15:31
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Wink

Rows of temporary table was deleted on commit (autocommit):

Code:
DECLARE GLOBAL TEMPORARY TABLE session.fred
(dept SMALLINT NOT NULL
,avg_salary DEC(7,2) NOT NULL
,num_emps SMALLINT NOT NULL)
on commit preserve rows;
Lenny
Reply With Quote
  #5 (permalink)  
Old 07-19-10, 15:44
smartcooldevil smartcooldevil is offline
Registered User
 
Join Date: Jun 2010
Posts: 17
Thanks!!! It works.

Last edited by smartcooldevil; 07-19-10 at 16:07.
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