Joined: 11 Oct 2007 Posts: 1 Location: Kolkata, India
Can anybody tell how temporary tables can be used? I would like to know all the necessary steps required to use DB2 temporary tables in a program. Which one is a better approach - using a created temp. table or a declared temp. table? Would be very very thankful if I get a detailed answer.
Joined: 08 Jun 2007 Posts: 71 Location: Zoetermeer, the Netherlands
At my site they always use "declared". Dunno why.
It works great, I'm using it more and more. Just
EXEC SQL DROP TABLE SESSION.Q_TMP
EXEC SQL DECLARE
GLOBAL TEMPORARY TABLE SESSION.Q_TMP
( THIS SMALLINT NOT NULL DEFAULT 9
, THAT CHAR (006) NOT NULL
, WHATEVER CHAR (004) NOT NULL)
e.g. when you have a complex query where you need info from "outside DB2" just gather that info into such a table and include/join that in your query.
Be ware that DB2 will treat that whole query as dynamic SQL! (empty plan-table)