SQLServer to Oracle...
 

Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop

[Closed] SQLServer to Oracle help

8 Posts
3 Users
0 Reactions
79 Views
 Earl
Posts: 1902
Free Member
Topic starter
 

In SQLServer I can create a temp table on the fly by using

select *
INTO #Temp1
from Table1

What is the equiv in Oracle? Google leads me to Global temp tables but can I create these from a SELECT statement?

(Can't test this as i dont have oracle installed at the moment)


 
Posted : 10/11/2009 8:58 am
Posts: 1
Free Member
 

No you can't.
Global temp tables are session based tables.
These tables need to be defined beforehand.
The scope of data in these tables is for the duration of the session and only visible to the session.

Can I ask more about what it is you are trying to accomplish? As there maybe other ways of doing it.


 
Posted : 10/11/2009 9:08 am
 Earl
Posts: 1902
Free Member
Topic starter
 

Just been handed a Oracle script to be converted to run in SQLServer.

The script was missing the table def's where data is temporarly stored during processing (upto 1mil row). So to get it working in SQLServer I changed the 'INSERT' statement to a 'SELECT INTO' statement. It's all running now but i would like to complete the Oracle version of this script. By your reply, I will need to pre define the tables at the beginning.

Dont really want to use views as a number of queries are run over the temp tables.

Any advice is much appreciated.


 
Posted : 10/11/2009 9:45 am
Posts: 1
Free Member
 

Just been handed a Oracle script to be converted to run in SQLServer.

So, it's an Oracle script already? So why do you need to do any converting (to Oracle) on it?

Dont really want to use views as a number of queries are run over the temp tables.

The use of traditional "Views" will give you performance degradation.
Look into materialized views.

Looks like the use of a staging table or other design-time database object is unavoidable.

If you want to do the database object creation on-the-fly you might also want to look into the EXECUTE IMMEDIATE command.


 
Posted : 10/11/2009 10:31 am
Posts: 2591
Full Member
 

Be careful with "select * into" this can (but not always) result in sql server aggressively escalating the locks to table locks on the source tables. Also you end up with no indexes on your temp tables so any queries will likely be table scans (= bad performance). Bad performance on queries running in temp db can have an effect on everything else to do with this server.


 
Posted : 10/11/2009 11:01 am
 Earl
Posts: 1902
Free Member
Topic starter
 

Background. I work on a system that can be run on either SQLServer or Oracle.

Current site is SQLServer but one of the BA's here gave me a Oracle script they had from another site and wanted it run here.

The oracle script was incomplete as it didn't contain the table defs for the work/staging tables so I used the #temptable ability of SQLServer. I don't need to run it in Oracle now just wanted to include some tips in the script for when the BA pulls it out again on a oracle site the developer will have a head start.


 
Posted : 10/11/2009 11:17 am
Posts: 1
Free Member
 

In Oracle you can do

CREATE TABLE temp1 AS select x,y,z from temp2 ....

This will work on its own - but check out the full syntax to ensure you create the table in the right tablespace. You can even create the table as a session based table (a la SQL Server) that automatically gets dropped on close of session.

[url= http://developer.postgresql.org/pgdocs/postgres/sql-createtable.html ]Syntax Linky[/url]

Sounds like you need to run it as a sql script rather than something that belongs in the database schema.

bol.


 
Posted : 10/11/2009 11:30 am
Posts: 2591
Full Member
 

I seem to remember (and I'm not really up to speed on oracle these days) you can create global temporary tables in oracle. You will just need declare the tables first. But you should be able to script out most of that, saving you typing it all out.


 
Posted : 10/11/2009 11:32 am
 Earl
Posts: 1902
Free Member
Topic starter
 

This look like the ticket.

A session based CREATE TABLE temp1 AS select x,y,z from temp2 ....

Thanks very much folks.


 
Posted : 10/11/2009 12:16 pm