How can I IF NOT EXISTS CREATE Temp table in PLSQL?

Hello, how I Temp IF NOT EXISTS CREATE table in PLSQL? The following table must be created in the FIRST call inside a recursive function (you will see in QUESTION 2).

QUESTION 1:
CREATE a TEMPORARY TABLE GLOBAL TmpHierarchyMap
(
ID numeric (19.0) NOT NULL,
ParentId numeric (19.0) NOT NULL,
ChildId numeric (19.0) NOT NULL,
... more...
() on commit delete rows);

QUESTION 2: How to return a temporary table of a function?

For example, this is how I do at the moment, using the Nested Table.

RUN IMMEDIATELY ' CREATE OR REPLACE TYPE TmpHierarchyMapObjType AS OBJECT
(
ID numeric (19.0),.
ParentId numeric (19.0),.
ChildId numeric (19.0),.
... more...
); ';

RUN IMMEDIATELY ' CREATE OR REPLACE TYPE TmpHierarchyMapTableType AS TABLE OF THE TmpHierarchyMapObjType; "


FUNCTION to CREATE or REPLACE fnGetParentsTable
(
Number to the ObjectId,
ObjectClassifier varchar2
)
RETURN TmpHierarchyMapTableType
IS
TmpHierarchyMap TmpHierarchyMapTableType: = TmpHierarchyMapTableType();
ThisTempId varchar2 (32);
CURSOR spGetParents_cursor IS
SELECT
ID,
ParentId,
ChildId,
...
OF TMP_HIERARCHYMAP
WHERE TempId = ThisTempId;
BEGIN
SELECT sys_guid() IN the double ThisTempId;

spRecursiveGetParents (ObjectId, ObjectClassifier, ThisTempId);

FOR oMap in spGetParents_cursor LOOP
TmpHierarchyMap.Extend ();
TmpHierarchyMap (TmpHierarchyMap.Count): = TmpHierarchyMapObjType (oMap.Id
oMap.ParentId
oMap.ChildId
...
);


END LOOP;

DELETE FROM TMP_HIERARCHYMAP WHERE TempId = ThisTempId;

RETURN TmpHierarchyMap;

END fnGetParentsTable;



QUESTION 3: that the OVERALL word means? I read this temporary table is visible only for a particular database connection/session and are deleted automatically at the end of the session. I can only find this information in a discussion forum, but cannot find it in the doc Oracle, can someone point me in the right direction please?


Thank you very much!

REF:
http://StackOverflow.com/questions/221822/Sybase-developer-asks-how-to-create-a-temporary-table-in-Oracle
http://www.Oracle-base.com/articles/8i/TemporaryTables.php

devvvy wrote:
so if I CREATE a GLOBAL TEMPORARY TABLE twice the second pass of my recursive function what happens then...?

You do not create it inside your function.

You create the TWG once on your database outside the service and then just leave it there and use.

Tables of should not be created and declined in dynamically.

Only other database such as SQL Server engines use the concept of creation of temporary tables when executing the code. Oracle uses a methodology "create once, use every time that."

Tags: Database

Similar Questions

Maybe you are looking for