Questions tagged [global-temp-tables]

Global temporary tables are temporary tables visible to all sessions. The contents (and even the table depending on the DBMS) are automatically removed when the connection is closed.

Global temporary tables are visible to all sessions.

Syntax

For SQL Server

prefix of global temporary table names with a double number sign:

##table_name

For Firebird, Oracle and PostgreSQL

create global temporary table table_name (....);

Lifetime

For SQL Server

Global temporary tables are automatically dropped when the session that created the table ends and all other tasks have stopped referencing them. The association between a task and a table is maintained only for the life of a single Transact-SQL statement. This means that a global temporary table is dropped at the completion of the last Transact-SQL statement that was actively referencing the table when the creating session ended.

Official documentation

For Firebird, Oracle and PostgreSQL

Global temporary tables are created once and will exist until they are dropped using a DROP TABLE. The data in the GTT however is automatically removed when the session disconnects or when the transaction is committed.

74 questions
0
votes
1 answer

Table order not being preserved when putting it into a global temp table

So I have this database mail query, and this is basically the exact same format I always use and it always works as expected. However, with this latest query, the order by portion is not being transferred to the global temp, so when I received the…
user1452574
  • 485
  • 1
  • 6
  • 15
0
votes
0 answers

Data from cursor is not getting inserted in global temporary table

I try to call a procedure from another procedure which returns a cursor as OUT and tries to insert the cursor data into a temp table without success. create or replace PROCEDURE test_sp_1 ( IN_LGVID VARCHAR2, IN_CHNID …
0
votes
0 answers

Object Not Found when ASP.NET app is trying to access a stored procedure using global temp table

I have an ASP.NET application accessing an Oracle 12 database. I have written a stored procedure using a global temp table to help. The global temp table is created with 'ON COMMIT DELETE ROWS'. Basically the stored procedure does the…
0
votes
1 answer

The different 'on commit' setting with Oracle Global Temp Table

Would any one please advise on the mechanism behind the two different settings for the Oracle GTT? 1) on commit preserve rows 2) on commit delete rows For now I know there 'facts': a) the records inserted into these 2 types of GTT have different…
0
votes
1 answer

Temp table in postgresql is getting dropped at the end of the session. How to solve it?

At the end of the current session the table is getting dropped, and all the values is lost. What can I do to solve this issue?
0
votes
1 answer

PHP ORACLE GLOBAL TEMPORARY TABLE

----- PHP --------
Krishnan
  • 1
  • 2
0
votes
1 answer

SQL Server : use same name global temp tables in several stored procedures

I have several stored procedures that first delete, then populate a global temp table called ##DataOutput. That is not all that the stored procedures do - just at some point of their process, they must populate this global table with some data, that…
igorjrr
  • 790
  • 1
  • 11
  • 22
0
votes
1 answer

"Invalid object name" when using global temp table in stored procedure

I'm following several examples to use global temp table such as this & this I have following query to get data into a global temp table: DECLARE @SQL NVARCHAR(MAX) SET @SQL = N'SELECT * INTO ##tmpDraftTableData FROM ' +…
Koo SengSeng
  • 933
  • 3
  • 12
  • 31
0
votes
1 answer

How to dynamically Create TSQL table?

I am using SSMS 2012 and wanting to do something like this: If(Select count(*) from T1) > 0 Begin Select * into ##T3 from T2 end If(Select count(*) from T1) < 0 Begin Select * into ##T3 from T4 end The logic was created so that way I should…
user76595
  • 357
  • 5
  • 17
0
votes
1 answer

Use Temp Table to merge query results from different DBs

I need to extract data from different DBs into a single table. These DBs are all in the same Server and Instance and they have the same structure. One of the columns will be DB Name, the others come from the same table. I could write a query that…
0
votes
1 answer

oracle apex GTT preserve rows after logout

I have a GTT in my oracle apex application. CREATE GLOBAL TEMPORARY TABLE "SEARCH" ( "CODE" VARCHAR2(15 BYTE), "HEAD" VARCHAR2(100 BYTE), "BRCODE" VARCHAR2(3 BYTE) ) ON COMMIT PRESERVE ROWS ; But the GTT preserves it's rows…
Nidheesh
  • 802
  • 1
  • 21
  • 44
0
votes
2 answers

Inserting the results set of SQL Dynamic Pivot Query into Temporary Table

How can I insert into global temporary table the results of the dynamic t-sql query in which columns is not fixed. See below for the table definition, value insertion and the t-sql for pivot query. /****** Object: Table [dbo].[ProdOrders] Script…
Eliseo Jr
  • 141
  • 3
  • 15
0
votes
1 answer

Returning Object Type from Oracle Procedure by partially populating it?

I have created an Object Type in Oracle as below: CREATE OR REPLACE TYPE Generic_MDMU_Scrub_Cols_OBJ as Object ( i_strTypeOfEntry varchar2(50), ID_SCRUB number, NM_DATA_COL1 varchar2(50), NM_DATA_COL2 varchar2(50), NM_DATA_COL3…
0
votes
0 answers

how to solve global temp table in windows azure

i am using global temp in my sql stored procedure when i upload into azure it is not working, can anyone please help me to solve this issue please check the below code had problem DECLARE @Q1 VARCHAR(MAX) SET @Q1='SELECT * INTO ##FINAL …
0
votes
1 answer

Declare temp table inside UserDefined Function in DB2 AS400

How to create user defined function with declare temporary table in AS400? I can't create a temporary table under parent procedure, because i'm using Parallel Jobs. So i need to create temporary table inside function only helps me. Did anybody knows…
Vivek Harry
  • 419
  • 3
  • 11
  • 25