dbTalk Databases Forums  

Execute Immediate

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Execute Immediate in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
janis
 
Posts: n/a

Default Execute Immediate - 11-19-2009 , 01:56 AM






Hi, could someone help me with execute immediate and the temp table

declare local temporary table #temp(name char(20));
execute immediate('my query here')
select * from #temp

what if there are 2 applications who start a stored procedure with
execute immediate right after each other ?
Will the data in the temp table be overwritten ?
How to avoid that ?

Reply With Quote
  #2  
Old   
Bofcilo
 
Posts: n/a

Default Re: Execute Immediate - 11-19-2009 , 03:01 AM






On Nov 19, 8:56*am, janis <jani... (AT) gmail (DOT) com> wrote:
Quote:
Hi, could someone help me with execute immediate and the temp table

* declare local temporary table #temp(name char(20));
* execute immediate('my query here')
select * from #temp

what if there are 2 applications who start a stored procedure with
execute immediate right after each other ?
Will the data in the temp table be overwritten ?
How to avoid that ?
From SQL usage.pdf

Temporary table Data in a temporary table is held for a single
connection only. Global temporary
table definitions (but not data) are kept in the database until
dropped. Local temporary table definitions
and data exist for the duration of a single connection only. For more
information about temporary tables,
see “Working with temporary tables” on page 87.

From SQL reference.pdf

CREATE LOCAL TEMPORARY TABLE table-name
( { column-definition [ column-constraint … ] | table-constraint |
pctfree }, … )
[ ON COMMIT { DELETE | PRESERVE } ROWS | NOT TRANSACTIONAL ]
pctfree : PCTFREE percent-free-space
percent-free-space : integer

.....
Remarks
In a procedure, use the CREATE LOCAL TEMPORARY TABLE statement,
instead of the DECLARE
LOCAL TEMPORARY TABLE statement, when you want to create a table that
persists after the procedure
completes. Local temporary tables created using the CREATE LOCAL
TEMPORARY TABLE statement
remain until they are either explicitly dropped, or until the
connection closes.
Local temporary tables created in IF statements using CREATE LOCAL
TEMPORARY TABLE also persist
after the IF statement completes.
......
DECLARE LOCAL TEMPORARY TABLE table-name
( { column-definition [ column-constraint … ] | table-constraint |
pctfree }, … )
[ ON COMMIT { DELETE | PRESERVE } ROWS
Quote:
NOT TRANSACTIONAL ]
pctfree : PCTFREE percent-free-space
percent-free-space : integer

Well temp table is PER connection. Other connection could not "see"
data from temp table created by another user.

See SQL usage.pdf for more details.

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.