Working with temp tables in PL/SQL process
753504Feb 24 2010 — edited Feb 24 2010So I’m trying to write a process in PL/SQL and I’m having some difficulty. Here’s what I need to do:
- Create some temp tables
- Put data in them
- Use the data in the temp tables to populate the main report table
- Drop the temp tables
I’m running into some problems when I try to create the tables. If I do it like I would in SQL Server:
SELECT Field1, Field2
INTO TempTable1
FROM
…
Then I get an error saying TempTable1 doesn’t exist. If I say:
CREATE TABLE TempTable1 AS
SELECT Field1, Field2
FROM
…
Then I get “Found CREATE, Expecting CASE or another statement”. I know that in order to truncate or drop tables in a PL/SQL I have to use EXECUTE IMMEDIATE. Do I need to do the same thing for creating a table? If that’s the case, how would I use execute immediate on a multi-line query with apostrophe’s in it?
Thanks!