473,583 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing an already existing temporary table

I have read many many messages about temporary tables and stored
procedures. Still, I am struggling with a simple concept. I have a
java program which creates a temporary table. I now want to access
(read) this table in a stored procedure (written in SQL). This stored
procedure is called from the same java program. My question is - how
do I "compile" the stored procedure and avoid the error message:
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0204N "SESSION.ALERTS MASSUPDATES" is an undefined name. LINE
NUMBER=15.
SQLSTATE=42704

I am running DB2 V8 on Linux.

Thanks so much
Mike Hubbard
Nov 12 '05 #1
7 7952
You'd have to make anything referencing the table dynamic sql (build the
select in a string var, and the execute immediate on it).

Mike Hubbard wrote:
I have read many many messages about temporary tables and stored
procedures. Still, I am struggling with a simple concept. I have a
java program which creates a temporary table. I now want to access
(read) this table in a stored procedure (written in SQL). This stored
procedure is called from the same java program. My question is - how
do I "compile" the stored procedure and avoid the error message:
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0204N "SESSION.ALERTS MASSUPDATES" is an undefined name. LINE
NUMBER=15.
SQLSTATE=42704

I am running DB2 V8 on Linux.

Thanks so much
Mike Hubbard

Nov 12 '05 #2
Mike,

The declared global temp (aka DGTT) has to exist when you create the
stored procedure.

In my experience customers throw the declarations into a procedure of
it's own, e.g.

CREATE PROCEDURE setup_temps()
BEGIN
DECLARE GLOBAL TEMPORARY TABLE SESSION.T1(c1 INT);
END
%

CALL setup_temps();

CREATE PROCEDURE myproc()...

So whenever you run a CREATE PROCEDURE you would precede it with a
CALL setup_temps();

And in your App you throw in the same CALL:
....
CALL setup_temps();
.....
CALL myproc();
....

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
Mike Hubbard wrote:
I have read many many messages about temporary tables and stored
procedures. Still, I am struggling with a simple concept. I have a
java program which creates a temporary table. I now want to access
(read) this table in a stored procedure (written in SQL). This stored
procedure is called from the same java program. My question is - how
do I "compile" the stored procedure and avoid the error message:
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0204N "SESSION.ALERTS MASSUPDATES" is an undefined name. LINE
NUMBER=15.
SQLSTATE=42704


Besides Serge's and Sean's remarks, there is yet another way:

Have one procedure (or normal statement) create the temp table, and in the
body of the stored procedure that you want to create, you can do this:

CREATE PROCEDURE ...
BEGIN
IF 1 = 0 THEN
DECLARE GLOBAL TEMPORARY TABLE mytemp ...
END IF

-- now you can use "mytemp"
END

That way, you avoid the SQL0204 but the temp table is not created inside the
procedure. At execution time, the already existing temp table is used
instead.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #4
I go from very frustrated to having 3 great options. Thanks so much to everyone.

Mike
Knut Stolze <st****@de.ibm. com> wrote in message news:<c5******* ***@fsuj29.rz.u ni-jena.de>...
Mike Hubbard wrote:
I have read many many messages about temporary tables and stored
procedures. Still, I am struggling with a simple concept. I have a
java program which creates a temporary table. I now want to access
(read) this table in a stored procedure (written in SQL). This stored
procedure is called from the same java program. My question is - how
do I "compile" the stored procedure and avoid the error message:
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0204N "SESSION.ALERTS MASSUPDATES" is an undefined name. LINE
NUMBER=15.
SQLSTATE=42704


Besides Serge's and Sean's remarks, there is yet another way:

Have one procedure (or normal statement) create the temp table, and in the
body of the stored procedure that you want to create, you can do this:

CREATE PROCEDURE ...
BEGIN
IF 1 = 0 THEN
DECLARE GLOBAL TEMPORARY TABLE mytemp ...
END IF

-- now you can use "mytemp"
END

That way, you avoid the SQL0204 but the temp table is not created inside the
procedure. At execution time, the already existing temp table is used
instead.

Nov 12 '05 #5
Correct. This "pseudo-pragma" approach does have an achilles-heel however.
It lies in the fact that the definitoion for the DGTT is now not
centralized.

CREATE PROCEDURE p1(OUT c3 INT)
BEGIN
DECLARE c1 INT;
DECLARE c2 INT DEFAULT 5;
DECLARE c3 INT;
IF 1 = 0 THEN
DECLARE GLOBAL TEMPORARY TABLE SESSION.T1
(c1 INT);
END ID;

SELECT c2 + c1 INTO c3 FROM SESSION.T1;
END
@
DECLARE GLOBAL TEMPORARY TABLE SESSION.T1
(c1 INT, c2 INT)
@
INSERT INTO SESSION.T1 VALUES (1, 2)
@
CALL p1(?)
=> c3: 6

Good luck debugging that one.
Other scenarios are implicit bind errors.
The SQL/PSM standard requires variables to be resolved form the inside out.
I.e. first DB2 will try to bind c2 to the table. Only if that fails it
binds to the variable c2 (moving from the inner most compount towards
the parameters (and in some future version to global variables).
The decision what is part of the SQL Query and what is a variable of
sorts is made at CREATE PROCEDURE time. It is irrevocable.
So if you pass in another signature, add a column to a table, doesn't
matter. DB2 has made up its' midn on who is who.

It's one of those things where the SQL Standard isn't exactly
encouraging usability. Read: It pays to have a naming convention.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #6
Serge,

Couldn't

CALL setup_temps();

simply be put into myproc() ??

Thus relieving the App. of the CALL myproc(); ?

also, would this then allow myproc() to be implemented
as static sql?
- a problem we had with temp tables were that they precluded
the procedures from being static.

I'll try anyway.

Thanks.

Paul.

Serge Rielau <sr*****@ca.e ye-be-em.com> wrote in message news:<c5******* ***@hanover.tor olab.ibm.com>.. .

So whenever you run a CREATE PROCEDURE you would precede it with a
CALL setup_temps();

And in your App you throw in the same CALL:
...
CALL setup_temps();
....
CALL myproc();
...

Cheers
Serge

Nov 12 '05 #7
Paul,

If the temp table does not exist when you create the procedure then
the you need to use dynamic SQL.
However. If you do the CALL in your DDL script, then the procedure will
create just fine with static SQL.
This does not preclude you from embedding the CALL into the stored
procedure for execution.

Note that all statemenst that involve temp tables will be compiled on
the fly once the procedure executes for the first time and recompiled
everytime the temp gets recreated.
This technique is liek dynamic SQL in a way, but it observes
conservative semantics (timestamp, function reolution, schema, path, ...).
You find it explained in VALIDATE RUN under BIND or PREPARE.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3375
by: Yannick Turgeon | last post by:
Hello all, I'm using SS2K on W2K. Brieffing: Many months ago, I created a stored procedure only used by those with admin rights in SS. Now, someone else (without admin rights) has to run it. I gave him rigth to execute the SP but, at the second and more execution, he got a error message concerning a temp table already existing (see...
0
2777
by: nedbollard | last post by:
Hi, Having checked out a declared (rather than created) temporary table successfully in SPUFI, I have hit a problem in running the same SQL in the cobol prog I am ameding to use it. I have: existing SQL declare temporary table insert in temporary table
1
2623
by: Yaro | last post by:
Hello DB2/NT 8.1.6 In procedure (SQL) I declare GLOBAL TEMPORARY TABLE. Sometimes this procedure is called twice a session and error creating table occure. I know, I can create table on session begin. I think I can check in procedure existing this table and declare or not it. Unfortunately I cannot find how do it. I don't see item in...
4
12028
by: prasad | last post by:
I am getting sql error during binding a program which access a temporary table. The temporary table declaration and access methods are given below. EXEC SQL DECLARE GLOBAL TEMPORARY TABLE TEM88 LIKE SYSIBM.SYSDUMMY1 END-EXEC. EXEC SQL INSERT INTO TEM88 SELECT * FROM SYSIBM.SYSDUMMY1 END-EXEC.
3
9413
by: Joe Weinstein | last post by:
Hi all. I am debugging a JDBC application. I find that a certain query that has an order-by clause fails with a SQL1585N A system temporary table space with sufficient page size does not exist. I can understand if there is not enough room for the temp data for sorting, but why should the page *size* matter? thanks, Joe Weinstein at...
6
3310
by: gimme_this_gimme_that | last post by:
I'm new to DB2 ... The following statement results in a SQL1585N message : "A system temporary table space with sufficient page size does not exist" Note that the column FIELD_DETAIL is a BLOB. Is there something inefficent about the SQL and CASE statement below that makes this error occur?
5
2994
by: Adam W. Saxton | last post by:
We have a few existing stored procedures which create a Global Temporary Table (##), do some work on the table and then delete the table. The issue we have is that if our Server application is using these is running and then our Web application fires off, the Temp table is getting deleted. My thought was to change the Global Temporary...
15
16162
by: OfficeDummy | last post by:
Hello all! I searched the Internet and this forum for a similar problem, but I found no help... Also, I'm a complete newbie to the fascinating world of programming, VBA and Access, so my question can very well be very stupid. The tasks are: 1)Import an Excel table into Access 2)Add a new column and fill it with variables of date/time...
3
2058
by: sonysunny | last post by:
Hai, I have a temporary table created in a stored procedure.How can i access that temporary table from another stored procedure. thanks in advance.
0
7895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5701
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3843
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.