dbTalk Databases Forums  

Determining Existance of Temporary Table.

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


Discuss Determining Existance of Temporary Table. in the sybase.public.sqlanywhere.general forum.



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

Default Determining Existance of Temporary Table. - 12-05-2003 , 09:41 AM






Does anyone know how to test if a temporary table exists?



Reply With Quote
  #2  
Old   
Hartmut Branz
 
Posts: n/a

Default Re: Determining Existance of Temporary Table. - 12-05-2003 , 10:08 AM






Just: select 1 from temptab

--
Hartmut Branz
International and Sustaining Engineering
iAnywhere Solutions


Maggie Lastovica wrote:

Quote:
Does anyone know how to test if a temporary table exists?




Reply With Quote
  #3  
Old   
Mark Culp
 
Posts: n/a

Default Re: Determining Existance of Temporary Table. - 12-05-2003 , 11:47 AM



Try a variation of this:

alter function check_for_foo ()
returns int
begin
declare table_not_found exception for sqlstate '42W33';
declare tmp int;
begin
select first 1 into tmp from foo;
exception
when table_not_found then
select 0 into tmp;
end;
return tmp
end;
go
select check_for_foo()

--
Mark Culp
ASA Development
-------------------------------------------------------------------------
** Whitepapers, TechDocs, bug fixes are all available through the **
** iAnywhere Developer Community at http://www.ianywhere.com/developer **
-------------------------------------------------------------------------
* <<<<< Please always include the ASA version and build number >>>>> *
* <<<<< _and_ the operating system version that you are using >>>>> *
-------------------------------------------------------------------------

Maggie Lastovica wrote:
Quote:
Does anyone know how to test if a temporary table exists?

Reply With Quote
  #4  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: Determining Existance of Temporary Table. - 12-05-2003 , 12:08 PM



I have only tested this function in 9.0.0.1235. It returns 1 if the
table name is OK, 0 otherwise. It is a horrible kludge; there should
be something easier ...

CREATE FUNCTION f_table_is_ok
( IN @table_name VARCHAR ( 128 ) )
RETURNS INTEGER
ON EXCEPTION RESUME
BEGIN
DECLARE @dummy INTEGER;
EXECUTE IMMEDIATE STRING (
'SELECT TOP 1 1 INTO @dummy FROM ',
@table_name,
' ORDER BY 1' );
IF SQLSTATE IN ( '00000', '02000' ) THEN
RETURN 1
ELSE
RETURN 0
END IF;
END;

BEGIN
DECLARE LOCAL TEMPORARY TABLE tt ( c INTEGER );
DECLARE LOCAL TEMPORARY TABLE "t t" ( c INTEGER );
SELECT f_table_is_ok ( 'asdf' );
SELECT f_table_is_ok ( 'tt' );
SELECT f_table_is_ok ( '"t t"' );
SELECT f_table_is_ok ( '"SYS"."SYSTABLE"' );
END;


Breck

On 5 Dec 2003 07:41:37 -0800, "Maggie Lastovica"
<m.lastovica (AT) ssss (DOT) com> wrote:

Quote:
Does anyone know how to test if a temporary table exists?

--
bcarter (AT) risingroad (DOT) com
Mobile and Distributed Enterprise Database Applications
www.risingroad.com


Reply With Quote
  #5  
Old   
Serge Gavrilov
 
Posts: n/a

Default Re: Determining Existance of Temporary Table. - 12-08-2003 , 06:11 AM



Just call function object_id( 'name_of_the_table' ). It will return null
if there are not table with name 'name_of_the_table'.

Best regards, Serge Gavrilov.

Maggie Lastovica wrote:
Quote:
Does anyone know how to test if a temporary table exists?




Reply With Quote
  #6  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: Determining Existance of Temporary Table. - 12-08-2003 , 08:22 AM



object_id does not work for temporary tables.

Breck

On 8 Dec 2003 04:11:56 -0800, Serge Gavrilov <sergegavrilov (AT) mail (DOT) ru>
wrote:

Quote:
Just call function object_id( 'name_of_the_table' ). It will return null
if there are not table with name 'name_of_the_table'.

Best regards, Serge Gavrilov.

Maggie Lastovica wrote:
Does anyone know how to test if a temporary table exists?


--
bcarter (AT) risingroad (DOT) com
Mobile and Distributed Enterprise Database Applications
www.risingroad.com


Reply With Quote
  #7  
Old   
Serge Gavrilov
 
Posts: n/a

Default Re: Determining Existance of Temporary Table. - 12-09-2003 , 10:47 AM




Breck Carter [TeamSybase] wrote:
Quote:
object_id does not work for temporary tables.
It works for the GLOBAL TEMPORARY TABLEs

Best regards, Serge Gavrilov



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.