Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UPDATE - Need a Temporary table?

blueoraMar 25 2010 — edited Mar 31 2010
Hi,

I'm encountered with a strange situation here.
While I'm trying to run an update it's running for hours. But, when as an alternative I create a dummy table and update using it, it executes instantly.
I'm not sure what's happening.

Though, I would like to know the cause, help me with the solution. Can I use WITH clause to fake temporary table?
(I tried using it but it seems it is not supported with UPDATE)
--running for hours
   UPDATE  table tab
   SET  (col1, col2, col3, col4)
      = (SELECT  col1, col2, col3, col4
           FROM  table_a
                 INNER JOIN table_b ON join_condition
                 INNER JOIN table_c ON join_condition
           WHERE  tab.id = table_a.id
           );
           
--runs in seconds
SELECT  col1, col2, col3, col4
           FROM  table_a
                 INNER JOIN table_b ON join_condition
                 INNER JOIN table_c ON join_condition;
                 
--runs in seconds
CREATE TABLE data_source AS
SELECT  table_a.id, col1, col2, col3, col4
           FROM  table_a
                 INNER JOIN table_b ON join_condition
                 INNER JOIN table_c ON join_condition;

--runs in seconds
   UPDATE  table tab
   SET  (col1, col2, col3, col4)
      = (SELECT  col1, col2, col3, col4
           FROM  data_source
           WHERE  tab.id = data_source.id
           );

[\code]

It updates around 10,000 rows of total 30,000 rows.

+As of now I may not be able to provide any database stats (explain plan etc.). Also, it's better if I can avoid any DDL. Please bear with me.+

I'm using oracle 11g.

Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2010
Added on Mar 25 2010
6 comments
1,563 views