In SQL Server, I'm used to creating a #temp
table for temporary storage in a complex stored procedure. Not wanting to clutter up the system, I DROP
the table when done.
However, if I do the same in Oracle:
CREATE GLOBAL TEMPORARY TABLE Temp.RecordsToBeDeleted
(PK INT NOT NULL PRIMARY KEY, Value VARCHAR2(10) NOT NULL)
-- Populate Temp.RecordsToBeDeleted
-- Use Temp.RecordsToBeDeleted
DROP TABLE Temp.RecordsToBeDeleted
...in one stored procedure, and another stored procedure does something similar and also uses the name Temp.RecordsToBeDeleted
, they could collide.
The actual data in the table will not be visible across stored procedures, but the schemas could be different, or I could DROP
one while the other is running.
Is there an established best practice for this? I could prefix each table name with the name of the stored procedure, but that's clumsy. I could treat GTTs as first-level objects, created with the rest of the schema rather than being created and dropped as needed, but that would increase maintenance; stored procedures would no longer be wholly self-contained.