473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Re: Temp table in Procedure

The Table tt_local will be created when you execute the procedure.
The table does not exist when you compile it.

There are two options

1. Create the global temporary table manually
Remove the creation of the table from the proc and then compile it.
2. Run the insert also as dynamic sql.
Remember dynamic sqls don't go through semantic check at compile
time.
(that happens during run time)

I myself prefer the first solution, Since condition like yours were
one of the reasons why conecept of global temporary table was created.

SQLcreate or replace procedure test
2 as
3 begin
4 EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE tt_Local(ID
VarChar2(38)) ON COMMIT PRESERVE';
5
6 INSERT INTO tt_Local
7 SELECT
8 empno
9 FROM
10 emp;
11 end;
12 /

Warning: Procedure created with compilation errors.

SQLshow errors
Errors for PROCEDURE TEST:

LINE/COL ERROR
-------- -----------------------------------------------------------------
6/4 PL/SQL: SQL Statement ignored
6/16 PLS-00201: identifier 'TT_LOCAL' must be declared
SQ*@b.sql
SQLcreate or replace procedure test
2 as
3 stmt varchar2(2000);
4 begin
5 EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE tt_Local(ID
VarChar2(38)) ON COMMIT PRESERVE';
6
7 stmt := 'INSERT INTO tt_Local SELECT empno FROM emp';
8 execute immediate stmt;
9 end;
10 /

Procedure created.

SQL>

The example below has wrong syntax for create global temporary table
but still compiles since the semantic check for dynamic sqls are done
during run time not compile time

SQ*@b.sql
SQLcreate or replace procedure test
2 as
3 stmt varchar2(2000);
4 begin
5 EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE tt_Local(ID
VarChar2(38)) COMMIT PRESERVE';
6
7 stmt := 'INSERT INTO tt_Local SELECT empno FROM emp';
8 execute immediate stmt;
9 end;
10 /

Procedure created.

SQL>

Hope this helps

amit

de**@rheal.com (Debu Das) wrote in message news:<29**************************@posting.google. com>...
Hi Friends,

In my stored procedure i am trying to create a temp table, populate
some data in it and then want to use it in the query.

This is how i am trying to do

EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE tt_Local(ID
VarChar2(38),Name VarChar2(50)) ON COMMIT PRESERVE';

INSERT INTO tt_Local
SELECT
ID,
NAME
FROM
SCHEMATABLE
WHERE
ID = SuperclassID;

After this i want this tt_Local table to be used in the query which i
will open it in a ref_cursor and send as a output paramaeter of the
stored procedure.

I am getting this Compilation errors

Error: PL/SQL: ORA-00942: table or view does not exist
Error: PL/SQL: SQL Statement ignored

################################################## ##################
I just tried to create the temporary table in the procedure with the
EXECUTE IMMEDIATE it got complied after that i tried to run the
procedure then i got this error
ORA-01031: insufficient privileges

Any information provided will be greatly appreciated.

Thanks in advance,

Debu
Jun 27 '08 #1
0 4657

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

Similar topics

1
by: Per | last post by:
Why cant I use the same temptable name i a stored procedure after i have droped it? I use the Pubs database for the test case. CREATE PROCEDURE spFulltUttrekk AS SELECT * INTO #temp FROM...
2
by: Tim Pascoe | last post by:
I'm relatively new to SQL-Server, and I have a quick question about temporary tables. I am using a function from Erland Sommarskog's excellent article about arrays in SQL server. Erland's...
0
by: joe pribele | last post by:
I have this stored procedure that takes some xml as input. What I need to is use xml as a table so that I can join other tables to the xml and get information back that matches the criteria. I...
0
by: gwaddell | last post by:
I have a stored procedure that is loading data into a global temp table. Here is all the code for that stored procedure. CREATE PROCEDURE AS SET NOCOUNT ON BEGIN
1
by: Lauren Quantrell | last post by:
I have read the newsgroups and see this is a common issue but I saw no resolution for it: I have an Access2K frotn end and SQL Server 2K backend. In access, I create a temp table using code in a...
1
by: BigD | last post by:
This all centers around an Access Data Project I have a stored procedure that aggregates events stored in a table based on intervals I specify. I have a form that supplies parameters for the...
6
by: betbubble | last post by:
I need help on two questions: 1. Is temp table the only way to pass recordsets from a nested stored procedure to a calling stored procedure? Can we avoid temp tables in this case? 2. Are...
2
by: kizmar | last post by:
You'll have to excuse me as I'm familiar with T-SQL (SQL Server), not so much DB2 when creating stored procedures... I'm trying to create a procedure where I build multiple temp tables (DECLARE...
1
by: romV | last post by:
Hi, I have a procedure that creates the global temp table (##temp) inside a procedure which is populated with data when it is run for the first time. And when the procedure is executed second time,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.