05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 10 ■ DATABASE TABLES 405<br />

SESSION_CNT TRANSACTION_CNT<br />

----------- ---------------<br />

14 0<br />

ops$tkyte@ORA10G><br />

ops$tkyte@ORA10G> disconnect<br />

Disconnected from <strong>Oracle</strong> <strong>Database</strong> 10g Enterprise Edition Release 10.1.0.3.0<br />

With the Partitioning, OLAP <strong>and</strong> Data Mining options<br />

ops$tkyte@ORA10G> connect /<br />

Connected.<br />

Since we’ve started a new session, we’ll see no rows in either table:<br />

ops$tkyte@ORA10G> select session_cnt, transaction_cnt<br />

2 from ( select count(*) session_cnt from temp_table_session ),<br />

3 ( select count(*) transaction_cnt from temp_table_transaction );<br />

SESSION_CNT TRANSACTION_CNT<br />

----------- ---------------<br />

0 0<br />

If you have experience with temporary tables in SQL Server <strong>and</strong>/or Sybase, the major<br />

consideration for you is that instead of executing SELECT X, Y, Z INTO #TEMP FROM SOME_TABLE to<br />

dynamically create <strong>and</strong> populate a temporary table, you will<br />

• Create all your global temporary tables once, as part of the application installation, just<br />

as you create permanent tables.<br />

• In your procedures, simply INSERT INTO TEMP (X,Y,Z) SELECT X,Y,Z FROM SOME_TABLE.<br />

Just to drive home the point, the goal here is to not create tables in your stored procedures<br />

at runtime. That is not the proper way to use temporary tables in <strong>Oracle</strong>. DDL is an<br />

expensive operation; you want to avoid doing that at runtime. The temporary tables for an<br />

application should be created during the application installation—never at runtime.<br />

Temporary tables can have many of the attributes of a permanent table. They may have<br />

triggers, check constraints, indexes, <strong>and</strong> so on. Features of permanent tables that they do not<br />

support include the following:<br />

• They cannot have referential integrity constraints. Neither can they be the target of a<br />

foreign key, nor can they have a foreign key defined on them.<br />

• They cannot have NESTED TABLE type columns. In <strong>Oracle</strong>9i <strong>and</strong> earlier, they cannot have<br />

VARRAY type columns either; this restriction was lifted in <strong>Oracle</strong> 10g.<br />

• They cannot be IOTs.<br />

• They cannot be in a cluster of any type.<br />

• They cannot be partitioned.<br />

• They cannot have statistics generated via the ANALYZE table comm<strong>and</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!