Oracle FAQ Your Portal to the Oracle Knowledge Grid

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Do triggers cause a context switch between SQL & PL/SQL

RE: Do triggers cause a context switch between SQL & PL/SQL

From: Jamadagni, Rajendra <>
Date: Tue, 01 Apr 2003 13:03:48 -0800
Message-ID: <>

A context switch is order because a trigger is a pl/sql object ...

if you can change the trigger ... instead of count(*) try using exists assuming you have a usable index ...

select count(*)
  into numrows
from dual
where exists ( select 1

                from ApplicationFormCriteria
               where ApplicationFormCriteria.applicationFormId =

If you have an index on "ApplicationFormCriteria.applicationFormId", this should fly ... and still accomplish what you need.

The basic problem here is the developer doesn't understand the question.

If the question is "Is there at-least one row that mayches a given value so that I can restrict the delete"? then my solution is the right one.

If the question is "How many rows do I have matches a given value so I can ... "? then the SQL you have is the right one.

Looking at the pl/sql code, the question is the former one and the SQL used by the developer is the wrong one. When you do a count(*) oracle will search the table till the HWM, if the table is large, it will make lot of difference. Where the query above will stop after it finds the first matching row, most likely doing less work that the query you have.

You can say I am picking on the semantics, but see how much difference it makes?

Rajendra dot Jamadagni at nospamespn dot com All Views expressed in this email are strictly personal. QOTD: Any clod can have facts, having an opinion is an art !

Please see the official ORACLE-L FAQ:
Author: Jamadagni, Rajendra

Fat City Network Services    -- 858-538-5051
San Diego, California        -- Mailing list and web hosting services
To REMOVE yourself from this mailing list, send an E-Mail message
to: (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Received on Tue Apr 01 2003 - 15:03:48 CST

Original text of this message