Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> MERGE statement internals

MERGE statement internals

From: Edgar Chupit <chupit_at_gmail.com>
Date: Fri, 8 Oct 2004 22:24:31 +0300
Message-ID: <a8f0771c041008122429e23167@mail.gmail.com>


Dear List,

I'm facing strange oddity when tracing MERGE statements. For each MERGE statement I get one parse error of the "strange" query from dual. I would like to know why does Oracle needs to query dual and is it a bug that this query is incorrect.

The merge statement is like this:

merge /* */ into t1 d
 using ( select 1 x from dual union all select 2 x from dual union all select 3 x from dual ) s
 on (d.id = s.x)
 when
   matched then

      update set d.f = null
 when not matched then

      insert (id,f) values(s.x,1)

but it can be any merge statement, and that interesting query from dual for this statement looks like this:

SELECT 1 FROM DUAL WHERE d.id = s.

Naturally that this query will return parse error because it is constructed incorrectly, but then why does Oracle tries to parse it?

Here is an raw trace output (I've trimmed some unnecessary lines):

Oracle Database 10g Release 10.1.0.3.0 - Production System name: Linux

and the test case is like this:

drop table t1;
create table t1 (id integer, f integer); insert into t1 values (1,1);
insert into t1 values (2,1);
commit;

exec dbms_stats.gather_table_stats(ora_login_user,'T1');

exec dbms_support.start_trace(true,false);

merge /* */ into t1 d

   using ( select 1 x from dual union all select 2 x from dual union all select 3 x from dual ) s

   on (d.id = s.x)
   when

     matched then 
        update set d.f = null
   when not matched then
        insert (id,f) values(s.x,1)

/
-- 
Edgar
--
http://www.freelists.org/webpage/oracle-l
Received on Fri Oct 08 2004 - 14:21:41 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US